Skip to content

C-API cleanup for OpenCV 5.x (imgproc, highgui)#22754

Merged
alalek merged 23 commits intoopencv:5.xfrom
mshabunin:c-cleanup
Dec 14, 2022
Merged

C-API cleanup for OpenCV 5.x (imgproc, highgui)#22754
alalek merged 23 commits intoopencv:5.xfrom
mshabunin:c-cleanup

Conversation

@mshabunin
Copy link
Copy Markdown
Contributor

@mshabunin mshabunin commented Nov 6, 2022

C-API will be removed completely. This PR covers imgproc and highgui (in progress) modules.

Issues:

  • many functions are only tested via C-API - these tests must be rewritten (removed for now)
  • in some places C-API is used internally by OpenCV - ad-hoc solution is to "hide" (remove from public header/export) corresponding C-function
  • can not test (at least build) some affected platforms - iOS/OSX, MSVC, ... (highgui module)
  • several files in opencv_contrib are affected, separate patch will be provided
  • must be merged after C-API cleanup for OpenCV 5.x (imgproc, highgui) opencv_contrib#3370


for (int i = 0; i < GRID_AREA; i++) {
Size s = Imgproc.getTextSize(Integer.toString(i + 1), 3/* CV_FONT_HERSHEY_COMPLEX */, 1, 2, null);
Size s = Imgproc.getTextSize(Integer.toString(i + 1), 3/* cv::FONT_HERSHEY_COMPLEX */, 1, 2, null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Size s = Imgproc.getTextSize(Integer.toString(i + 1), Imgproc.FONT_HERSHEY_COMPLEX, 1, 2, null);

if (mShowTileNumbers) {
Imgproc.putText(mCells15[i], Integer.toString(1 + idx), new Point((cols / GRID_SIZE - mTextWidths[idx]) / 2,
(rows / GRID_SIZE + mTextHeights[idx]) / 2), 3/* CV_FONT_HERSHEY_COMPLEX */, 1, new Scalar(255, 0, 0, 255), 2);
(rows / GRID_SIZE + mTextHeights[idx]) / 2), 3/* cv::FONT_HERSHEY_COMPLEX */, 1, new Scalar(255, 0, 0, 255), 2);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(rows / GRID_SIZE + mTextHeights[idx]) / 2), Imgproc.FONT_HERSHEY_COMPLEX, 1, new Scalar(255, 0, 0, 255), 2);

int depth = test_mat[i][j].depth();
// j == 0 is for forward code, j == 1 is for inverse code
return (depth == CV_8U) ? (srgb ? 32 : 8) :
return (depth == CV_8U) ? (srgb ? 37 : 8) :
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it changed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came to conclusion that these thresholds have been chosen experimentally and after changing RNG seeds some tests can fail. We've observed the same problem with these tests in another PR: #16189 (comment)

I specifically moved this fix to separate commit, so it can be backported to 4.x later.

@asmorkalov
Copy link
Copy Markdown
Contributor

I propose to split the PR by the target module. Highgui part could be merged faster as there are not so many changes.

@mshabunin
Copy link
Copy Markdown
Contributor Author

@asmorkalov , while I tried to separate changes for each module it is possible that there could be commits affecting both of them. Thus splitting the PR can take more time and effort than reviewing it in one place. Modifications mostly do a mechanical replacement of one symbol with another.

#else
Mat binarized_img = thresh_img_new.clone(); // make clone because cvFindContours modifies the source image
#endif
detector.generateQuads(binarized_img, flags);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe deleting Mat binarized_img = thresh_img_new; and detector.generateQuads(thresh_img_new, flags); will be better

#else
Mat binarized_img = (useAdaptive) ? thresh_img : thresh_img.clone(); // make clone because cvFindContours modifies the source image
#endif
detector.generateQuads(binarized_img, flags);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

cvIsNaN(box.angle) || cvIsInf(box.angle) || box.angle < -180 || box.angle > 180 )
{
ts->printf( cvtest::TS::LOG, "Invalid CvBox2D or CvConnectedComp was returned by cvCamShift\n" );
ts->printf( cvtest::TS::LOG, "Invalid Box2D was returned by CamShift\n" );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Box2D -> RotatedRect

- Rectangular box: CV_SHAPE_RECT
- Cross: CV_SHAPE_CROSS
- Ellipse: CV_SHAPE_ELLIPSE
- Rectangular box: cv::SHAPE_RECT
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(it is in Java tab)
Rectangular box: Imgproc.SHAPE_RECT
Cross: Imgproc.SHAPE_CROSS
Ellipse: Imgproc.SHAPE_ELLIPSE

Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!
Tested manually following combinations on Linux:

  • GTK3 no OpenGL + mouse, hot keys
  • GTL2 + OpenGL
  • QT 5.9 + OpenGL
  • QT 5.9, no OpenGL + mouse, hot keys

@asmorkalov
Copy link
Copy Markdown
Contributor

@mshabunin Please squash commits. I'll merge the PR together with contrib.

@alalek alalek merged commit 8a62b03 into opencv:5.x Dec 14, 2022
@mshabunin mshabunin deleted the c-cleanup branch December 14, 2022 19:38
asmorkalov added a commit to asmorkalov/opencv that referenced this pull request Mar 5, 2024
asmorkalov added a commit to asmorkalov/opencv that referenced this pull request Mar 5, 2024
asmorkalov added a commit to asmorkalov/opencv that referenced this pull request Mar 5, 2024
asmorkalov added a commit to asmorkalov/opencv that referenced this pull request Mar 5, 2024
asmorkalov added a commit that referenced this pull request Mar 5, 2024
@asmorkalov asmorkalov mentioned this pull request Apr 1, 2024
klatism pushed a commit to klatism/opencv that referenced this pull request May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Code cleanup (e.g, drop legacy C-API, legacy unmaintained code)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants