How to detect the end point of the line from this image
Hey, im trying to detect the end points of the line from this image. And marking a cross at it. Can someone help me?
Hey, im trying to detect the end points of the line from this image. And marking a cross at it. Can someone help me?
an endpoint of your line has exactly 1 white neighbour, the others have 2.
so, you'll have to check the 8-neighbourhood of each white pixel, and count the white neighbours, if you end up with 1 -- you found an endpoint !
pts = cv2.findNonZero(im)
print(pts.shape)
## (114, 1, 2)
## note the weird, extra dimension in the middle
ends = []
for pt in pts:
on = 0
p=pt[0] ## access the point from a 2d array, see above
## 1 2 3
## 4 * 5
## 6 7 8
if im[p[1]+1,p[0]-1]>0: on +=1
if im[p[1]+1,p[0] ]>0: on +=1
## student project, -- your task here !
...
if on==1: ends.append(p)
print (ends)
[array([17, 12], dtype=int32), array([99, 87], dtype=int32)]
I'm sorry , i been trying very hard to understand the code u given me.. but i still dun quite get it
Asked: 2017-12-29 02:40:13 -0600
Seen: 719 times
Last updated: Dec 29 '17
Area of a single pixel object in OpenCV
how to understand which functions available in python bindings?
Problems installing opencv on mac with python
build problems for android_binary_package - Eclipse Indigo, Ubuntu 12.04
OpenCV DescriptorMatcher matches
Can't compile .cu file when including opencv.hpp
Weird result while finding angle
cv2.perspectiveTransform() with Python
Using OpenCV's stitching module, strange error when compositing images