Error cv2.threshold () (-210)

I am new to Python.

I want to determine the rotation of a text using the Fourier transform.

import cv2
import numpy as np
import matplotlib.pyplot as plot

img = cv2.imread ('Text_rot.bmp', cv2.CV_LOAD_IMAGE_GRAYSCALE)
afterFourier =  np.log (np.abs(np.fft.fft2 (img)))
ret1, th1 = cv2.threshold (afterFourier, 127, 255, cv2.THRESH_BINARY)

But this code does not work:

ret1, th1 = cv2.threshold (afterFourier, 127, 255, cv2.THRESH_BINARY)
error: ..\..\..\src\opencv\modules\imgproc\src\thresh.cpp:783: error: (-210) 

Why does this cause a "-210" error?

+5
source share
1 answer

OpenCV error codes can be found in . types_c.h

Error code -210 is defined as:

CV_StsUnsupportedFormat= -210, /**< the data format/type is not supported by the function*/

So, you need to cast your image to a data type uint8before passing it to cv2.threshold. This can be done using numpy using the method astype:

afterFourier = afterFourier.astype(np.uint8)

afterFourier afterFourier 8- , / , , .

+18

Source: https://habr.com/ru/post/1539968/


All Articles