基于openCV中轮廓/边缘的最佳对象识别算法是什么

时间:2019-08-23 08:11:53

标签: python opencv

我正在开发一个应用程序,该应用程序在任何情况下都需要根据对象的轮廓识别对象。到目前为止,如果对象具有简单的背景,我就可以识别出它们的轮廓,但是如果后面有诸如头部或面部之类的复杂物体,该算法将失败。

我正在使用县和matchShapes来做到这一点:

framecp = frame
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frame = np.uint8(frame)

# Defining counturs of the frames
ret, thresh = cv2.threshold(frame, 80, 255, 1)
counturs, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

# res - result, ind - saved index, index - index of countures in for loop
res = 0.36
ind = 0 
index = 0

# matching every shape with the given sample to find best result.
for shape in counturs:
    if cv2.matchShapes(shape, kcounturs[1], 1, 0.0) < res:
        res = cv2.matchShapes(shape, kcounturs[1], 1, 5)
        ind = index
        print(res)
    index = index + 1

# printing result to console, drawing contours and displaying result.
cv2.drawContours(framecp, counturs, ind, (0, 0, 200), 2)

我也曾尝试在其上应用canny,但效果不佳。我什至做了很好的老laplacian +模糊+平滑来获得更清晰和厚实的边缘,但这也是一个死胡同。那时我决定放弃这种算法。我还尝试了一些其他算法,但到目前为止,这对我来说效果最好。问题在于,为了优化性能,我不需要使用诸如ORB,SURF或SIFT之类的重量级算法,只需要对象的边缘,然后在框架中找到该边缘或轮廓即可。

0 个答案:

没有答案