Fill result of Canny edge detector opencv - opencv

Is there a way to fill the results of a Canny edge detector with white?
An alternative could be to detect whether a pixel or object is on the concave size of a curved edge.

Canny detects edges, it does not make any guarantees about generating closed contours. Thus, "filling" is not always defined for the result.
If by some other means you know that some area is enclosed in a continuous closed contour, you could use e.g. flood-fill to fill it.

Related

OpenCV Hough Detection finding inner circle

I'm trying to use Hough circle detection method to find all the circle as shown in the image(shown in image 1 and 2). Initially, I used canny and findContour method (shown in image 3). I'm still unsure which method will be more suitable.The problem with the canny and findContour method was that it didn't find all the circles as well as getting lot of noise. But when using the Hough circle detection, the circle is sometimes catching the outer perimeter instead of the inner as shown in image 2.
The canny+findcontour methods finds the circle contour well but has a lot of noise whereas Hough circle works well but the circles sometimes blends with the outer circle.
Hough circle
Hough circle-zoomed in
canny + findcontour method
I think you can get better results if you pre-process the image. First apply Otsu thresholding, if that doesn't work well use a manual value for threshold. After that use the cv.erode() function to get a crisp boundary. Then try to apply the Hough circle transform.
If performance is not an issue, another interesting thing would be to to look at Holistically Nested Edge Detection and then apply Hough circle transform.
Also have a look at the following:
https://www.learnopencv.com/filling-holes-in-an-image-using-opencv-python-c/
https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_watershed/py_watershed.html

line detection, when the gray value of contour and background is very similar

I am working on a project. In this project I need to use a robotic gripper to gripp a flange. This flange will be detected and located in a monocamera. This flange contour comes from a FOUP handling flange. What I need to do is to detect the most outer edge. Because that edge is determined by a CAD model. The internal edge is not useful.(image 0)
I have already tried to detect the edge by using bilateral filter and Canny detector. But this works not very well. Because the internal edge is more clear than the outer edge. The result is, there are many edges at the contour.
And that contour is also not continuous.
Image below is the oringinal image.
Those are the lines, which I need to detect.
This is the result from canny detector.
This is the original image for this flange.
Below is the edge image.
This edge detection I just use the canny detector in opencv.

Finding ROI for a periodic repetative fringe pattern

I am trying to detect ROI for a fixed repetitive pattern in an image using opencv C++.
The ROI which I am trying to find - is shown with red boundary as shown in the pic:
I tried canny edge detection after blurring but it detects edge of the vertical/horizontal black and white lines. This is not something I am trying to detect.
What is the best approach to my problem?
Since you're starting with a binary image you could use
findContours()
to get the contours for the individual strips. Since there are a couple of solitary pixels from noise you should then filter for size using
contourArea(contour)
and merge the points of all contours meeting your size criteria into a combined contour. Then get the bounding box for the combined contour:
boundingRect(combinedContour)

how to perform hough transformation for spesific angle range

I have been trying to detect and track vehicle in a video stream. Recently I decided to implement a hard-coded method which find out the shadow of a vehicle and detect entire vehicle with respect to tire position. At the end, I partially done with my implementation. Here is the video link of demonstration.
At the first step I used canny edge detector to subtract edge of the video frames.
Then I used hough transform funciton in opencv.
However this functions finds all the horizontal and vertical lines while I only interested in horizontal lines which are possibly shadow of the vehicle.
My question is how I can use hough line transform function where it only checks the lines which are in a spesific range of angle and within a spesific area. Is there any parameter that tresholds the angle ? Or should I implement the function by myself ?
Since you end up with a binary image after the Canny operation, it may be easiest to convolve the image with a simple horizontal Prewitt operator before applying the Hough transform:
1 1 1
0 0 0
-1 -1 -1
which will give you a map of the grayscale intensities of each pixel, with pixels along horizontal edge giving the strongest signal. The advantage of using only the horizontal operator is that vertical edges receive no amplification, horizontal edges receive maximum amplification, and any edge within 45° of horizontal should have a signal somewhere between the two. You can use the resulting image to decide which pixels from the Canny mask to keep when you apply the detect edges to the original image: If the Prewitt signal is above a certain threshold for a pixel, that pixel is assumed to be along a 'horizontal-enough' edge that gets kept, discard otherwise. I believe opencv has this feature, but it's trivial to implement if not.

Motion blur robust edge detection

I need to detect squares on an image (for AR marker detection). Squares are rotated in 3D (meaning their projection I'm seeing isn't really a square but a 4 sided polygon). My problem is that the polygons I need to detect are moving so they are subject to motion blur. Squares are black with a white margin so there's a high contrast.
My approach for detection was to detect edges (canny for example), find contours, approximate polygons and filter them by the number of sides and maybe some other geometrical constraints.
What approach would you recommend for detecting edges on an image with a motion blur?
Thanks
I would use Harris corner detection to detect the corner points and then use Hough transform to detect the lines. Using the position of the corners and lines it is possible to get the polygons.

Resources