Intelligent scissor for openCV.js#18344
Conversation
|
|
|
||
| CV_EXPORTS_W float local_cost(const Point& p, const Point& q, const Mat& gradient_magnitude, const Mat& Iy, const Mat& Ix, const Mat& zero_crossing); | ||
|
|
||
| CV_EXPORTS_W void find_min_path(const Point& start, Mat img, Mat zero_crossing, Mat gradient_magnitude, Mat Ix, Mat Iy, Mat& hit_map_x, Mat& hit_map_y); |
There was a problem hiding this comment.
This should be a class which computes all the intermediate buffers inside.
There was a problem hiding this comment.
Agreed.
imgproc module location is fine.
But we need to define "Algorithm" class for this task (see QRCodeDetector as reference).
API should be clear, simple and easy to use (instead of local functions with many parameters which are hard to use).
Also add documentation for that.
You have to install |
|
@mshabunin, sorry, forgot to respond. Issue was related to incorrect build arguments. Right is |
|
Please learn this topic: https://github.com/opencv/opencv/wiki/Coding_Style_Guide |
|
@SimpleVlad Do you have a chance to finish the patch? The work looks like abandoned. |
| This class is used to find the minimum path between points | ||
| of image. | ||
| */ | ||
| class CV_EXPORTS_W Intelligent_scissors |
| of image. | ||
| */ | ||
| class CV_EXPORTS_W Intelligent_scissors | ||
| { |
There was a problem hiding this comment.
Intelligent_scissors
Please learn and follow OpenCV naming conventions and other rules: https://github.com/opencv/opencv/wiki/Coding_Style_Guide
| */ | ||
| CV_WRAP Intelligent_scissors(); | ||
|
|
||
| CV_WRAP Intelligent_scissors(const int input_border); |
There was a problem hiding this comment.
input_border
type? size?
Please add documentation for this parameter
| protected: | ||
| int border; |
There was a problem hiding this comment.
Implementation details are not allowed in public headers.
Use PImpl design pattern.
|
|
||
| CV_WRAP void setBorder(const int input_border); | ||
|
|
||
| CV_WRAP void Intelligent_scissors_one_point(Mat img, OutputArray total_hit_map_x, OutputArray total_hit_map_y, const Point start_point); |
There was a problem hiding this comment.
Mat
InputArray must be used: https://github.com/opencv/opencv/wiki/Coding_Style_Guide
|
|
||
| threshold(img_canny, zero_crossing, 254, 1, THRESH_BINARY_INV); | ||
| Sobel(grayscale, Ix, CV_32FC1, 1, 0, 1); | ||
| Sobel(grayscale, Iy, CV_32FC1, 0, 1, 1); |
There was a problem hiding this comment.
Sobel() is used in Canny() implementation too.
Are parameters of these calls the same?
|
|
||
| // Compute gradients magnitude. | ||
| magnitude(Iy, Ix, gradient_magnitude); | ||
| minMaxLoc(gradient_magnitude, 0, &max_val); |
There was a problem hiding this comment.
max_val
define this variable right before its usage. No need to put it somewhere in the beginning.
| // Compute gradients magnitude. | ||
| magnitude(Iy, Ix, gradient_magnitude); | ||
| minMaxLoc(gradient_magnitude, 0, &max_val); | ||
| gradient_magnitude.convertTo(gradient_magnitude, CV_32F, -1/max_val, 1.0); |
There was a problem hiding this comment.
-1/max_val
Check for near-zero value is necessary before division.
| continue; | ||
| if (expand.at<uchar>(ty, tx) == 0) | ||
| { | ||
| Point q = Point(tx, ty); |
There was a problem hiding this comment.
-Point q = Point(tx, ty);
+Point q(tx, ty);
samples/cpp/intelligent_scissors.cpp
Outdated
| } | ||
| // static float local_cost(const Point& p, const Point& q, const Mat& gradient_magnitude, const Mat& Iy, const Mat& Ix, const Mat& zero_crossing) | ||
| // { | ||
| // float fG = gradient_magnitude.at<float>(q.y, q.x); |
There was a problem hiding this comment.
Remove dead code from repository.
platforms/js/opencv_js.config.py
Outdated
| 'fillPoly', 'fillConvexPoly'], | ||
| 'undistort','warpAffine','warpPerspective','warpPolar','watershed', 'Intelligent_scissors',\ | ||
| 'fillPoly', 'fillConvexPoly'], \ | ||
| 'Intelligent_scissors':['Intelligent_scissors', 'Intelligent_scissors_one_point', 'setBorder'], \ |
There was a problem hiding this comment.
Define create method. Not sure if bindings support C++ constructors
platforms/js/opencv_js.config.py
Outdated
| 'fillPoly', 'fillConvexPoly'], | ||
| 'undistort','warpAffine','warpPerspective','warpPolar','watershed',\ | ||
| 'fillPoly', 'fillConvexPoly'], \ | ||
| 'Intelligent_scissors': ['Intelligent_scissors', 'Intelligent_scissors_one_point', 'setBorder'], \ |
There was a problem hiding this comment.
Please align with 'CLAHE' (less whitespaces) and remove extra \ at the end
platforms/js/opencv_js.config.py
Outdated
| 'undistort','warpAffine','warpPerspective','warpPolar','watershed', \ | ||
| 'fillPoly', 'fillConvexPoly'], | ||
| 'undistort','warpAffine','warpPerspective','warpPolar','watershed',\ | ||
| 'fillPoly', 'fillConvexPoly'], \ |
platforms/js/opencv_js.config.py
Outdated
| 'pointPolygonTest', 'putText','pyrDown','pyrUp','rectangle','remap', 'resize','sepFilter2D','threshold', \ | ||
| 'undistort','warpAffine','warpPerspective','warpPolar','watershed', \ | ||
| 'fillPoly', 'fillConvexPoly'], | ||
| 'undistort','warpAffine','warpPerspective','warpPolar','watershed',\ |
|
@alalek, Do you know the source of this problem? https://pullrequest.opencv.org/buildbot/builders/precommit_docs/builds/28227 |
|
This happens when JS binding generator lost headers of used modules. |
|
Need to cherry-pick commit from PR #19059 (fix is targeted to 3.4 branch first) Need to squash commits and rebase first, because base commit is from 2020-04-24 |
Rebase master branch
|
|
||
| cvtColor(src, grayscale, COLOR_BGR2GRAY); | ||
| Canny(grayscale, img_canny, EDGE_THRESHOLD_LOW, EDGE_THRESHOLD_HIGH); | ||
| threshold(img_canny, zero_crossing, 254, 1, THRESH_BINARY_INV); |
There was a problem hiding this comment.
zero_crossing computation does not follow the article. Canny() is not used there.
See Section 3.1
| Ix.convertTo(Ix, CV_32F, 1.0 / 255); | ||
| Iy.convertTo(Iy, CV_32F, 1.0 / 255); |
There was a problem hiding this comment.
The gradient direction is the unit vector defined by Ix and Iy.
This code doesn't provide the normalized vector: Ix(pt)^2 + Iy(pt)^2 = 1
| float cost = cost_map.at<float>(p) + lcost(p, q, gradient_magnitude, Iy, Ix, zero_crossing); | ||
| if (processed.at<uchar>(q) == 1 && cost < cost_map.at<float>(q)) | ||
| { | ||
| removed.at<uchar>(q) = 1; |
There was a problem hiding this comment.
In article "updated" point is removed from "sorted" queue to be re-inserted again with new cost.
This code:
- removes point completely from processing queue L (see
if (removed.at<uchar>(p) == 0)condition above) - does not update "better" cost value
Article.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.