我正在尝试优化我的圈子识别脚本。 这个想法是按半径(从最大到最小)对 HoughCircle 函数 (cv2) 返回的圆进行排序。 例如:
circles=cv2.HoughCircles(image,bla....bla)
circles2=sorting_by_radius(circles) #your help is needed to do this
for c in circles2
do_my_istructions
我尝试了 .sort
方法和 np.argsort
但出了点问题。
最佳答案
代表 user3157906(以便应用代码格式)
解决了!
我犯的错误:
circles=cv2.HoughCircles(image,bla....bla)
circles2=sorted(circles,key=lambda x:x[2],reverse=true)
问题是每个圆的位置和半径信息存储在 circles[0]
所以正确的做法是:
circles=cv2.HoughCircles(image,bla....bla)
circles2=sorted(circles[0],key=lambda x:x[2],reverse=true)
关于Python:按半径对从 cv2 HoughCircles 返回的圆进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20908328/