Clicking on a point in an image finds the closest contour points
Update: As suggested. I added my current code that detects all boundaries of each shape (not desired) with another problem that these boundary lines can be a few pixels wide and form inside and outside countour to be recognized
Let say I click on a point inside wanted3 shape/contour (see second image). I would use C#.net OpenCV 2 and/or 3
One Note. The lines denoting shapes can be one or more pixel wide. I would like the recognized points to lay exactly in the middle of that line, so when I do another recognition of surrounding shape I will get an exact point for that shared line recognized in 2 contours
I want the closest contour recognized, that encompasses the pressed point with a mouse left click within it. There can however be a larger encompassing contour (not shown here; think of it as a county encompassing cities/places), and I just want the closest one recognized.
Whan I press inside wanted2 shape I want South-East border to have exactly the same discoverer contour points as wanted3 no matter how thick the bordering line is (so some calculation of where the middle point is necessaryl Thanks Rad
Sub ProcessImageAndUpdateGUI(sender As Object, arg As EventArgs)
Try
If (rdoImageFile.Checked = True) Then 'if the image file radio button is chosen . . .
Try
imgOriginal = New Image(Of Bgr, Byte)(txtFile.Text) 'get original image from file name in text box
Catch ex As Exception
Return
End Try
ElseIf (rdoWebcam.Checked = True) Then 'else if the webcam radio button is chosen . . .
Try
imgOriginal = capWebcam.QueryFrame() 'get next frame from webcam
Catch ex As Exception
Return
End Try
Else
'should never get here
End If
If (imgOriginal Is Nothing) Then 'if imgOriginal is null
Return 'bail
End If
'perform image smoothing
imgSmoothed = imgOriginal.PyrDown().PyrUp() 'Gaussian pyramid decomposition
imgSmoothed._SmoothGaussian(3) 'Gaussian smooth, argument is size of filter window
If (ckFilterOnColor.Checked = True) Then 'if filter on color check box is checked, then filter on color
imgGrayColorFiltered = imgSmoothed.InRange(New Bgr(dblMinBlue, dblMinGreen, dblMinRed), New Bgr(dblMaxBlue, dblMaxGreen, dblMaxRed))
imgGrayColorFiltered = imgGrayColorFiltered.PyrDown().PyrUp() 'repeat smoothing process after InRange function call,
imgGrayColorFiltered._SmoothGaussian(3) 'seems to work out better this way
ElseIf (ckFilterOnColor.Checked = False) Then 'if filter on color is not checked,
imgGrayColorFiltered = imgSmoothed.Convert(Of Gray, Byte)() 'then convert to gray without filtering
End If
'Dim grayCannyThreshold As Gray = New Gray(160) 'first Canny threshold, used for both circle detection, and line / triangle / rectangle detection
'Dim grayCannyThreshold As Gray = New Gray(200) 'first Canny threshold, used for both circle detection, and line / triangle / rectangle detection
Dim grayCannyThreshold As Gray = New Gray(240) 'first Canny threshold, used for both circle detection, and line / triangle / rectangle detection
Dim grayCircleAccumThreshold As Gray = New Gray(100) 'second Canny threshold for circle detection, higher number = more selective
Dim grayThreshLinking As Gray = New Gray(80) 'second Canny threshold for line / triangle / rectangle detection
'imgCanny = imgGrayColorFiltered.Canny(grayCannyThreshold, grayThreshLinking) 'Canny image used for line, triangle, rectangle, and polygon ...
@LorenaGdL I tried something (still learning). I will post some code soon. I could find all the inside and outside contour points of all boundary lines. I don't want all of contours, only one the closest. Another problem is that I would like to reduce the thickness to only 1 pixel so both inside and outside boundaries should meet. If somebody helps me he/she can be paid for this.
@LorenaGdL I added my current code. The language used is not important. I need some concrete steps.Tx.
Have you solved your problem? Please accept the answer if you solved the problem!
I don't have c++ environment to check, but based on the logic and provide picture it is sufficient. I didn't see if you discovered contour points used to draw the contour and what parameter regulates the number of them. Let me know if I missed it. Tx.