Python OpenCV Template Matching error

后端 未结 1 1824
醉梦人生
醉梦人生 2021-01-01 23:41

I\'ve been messing around with the OpenCV bindings for python for a while now and i wanted to try template matching, i get this error and i have no idea why

         


        
相关标签:
1条回答
  • 2021-01-02 00:33

    Pay attention to the error message:

    error: (-215) (depth == CV_8U || depth == CV_32F) && type == _templ.type() && _img.dims() <= 2 in function cv::matchTemplate

    It means the data type of the image should be CV_8U or CV_32F, and it should have 3 or less channels.

    If you don't know what CV_8U, CV_32F means, see this list.

    Probably you are passing numpy objects other than np.uint8 or np.float32. you can easily convert numpy dtype to 8-bit or 32-bit using:

    img.astype(np.float32)
    img.astype(np.uint8)
    

    Just pay attention that OpenCV expect CV_8U 8-bit data to be in the range 0..255 and CV_32F can be in any range.

    0 讨论(0)
提交回复
热议问题