怎么定位numpy二维数组的某些符合矩阵的行列

根据网上的代码,我能通过下面这段代码找图片的角点

   def test(filename):

    img = cv2.imread(filename)
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    gray = np.float32(gray)
    #图像转换为float32
    dst = cv2.cornerHarris(gray,2,3,0.01)
    #result is dilated for marking the corners, not important
    dst = cv2.dilate(dst,None)#图像膨胀
    # Threshold for an optimal value, it may vary depending on the image.
    #print(dst)
    #img[dst>0.00000001*dst.max()]=[0,0,255] #可以试试这个参数,角点被标记的多余了一些
    img[dst>0.01*dst.max()]=[0,0,255]#角点位置用红色标记

    #这里的打分值以大于0.01×dst中最大值为边界
    cv2.imshow('dst',img)
    if cv2.waitKey(0) & 0xff == 27:
        cv2.destroyAllWindows()


if __name__ == '__main__':
    #ImageFind('115.png',new_img='116.png')
    test('1211.png')
    

其中img[dst>0.01*dst.max()]=[0,0,255]这一句,img应该是一个numpy二维数组,怎么定位符合条件的这些矩阵的位置呢?就是图片上的小红点的横纵坐标。你们用代码测一下就知道了。

阅读 4.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题