Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cv2.threshold() error (-210)

I'm new to Python.

I want to define text rotation with help of Fourier transformation.

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 fails with:

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

Why does that cause a "-210" error?

like image 675
IvanovAndrew Avatar asked May 09 '14 19:05

IvanovAndrew


1 Answers

The OpenCV error codes can be looked up 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'll need to coerce your image into uint8 data type before passing it to cv2.threshold. This can be done with numpy using the astype method:

afterFourier = afterFourier.astype(np.uint8)

This will truncate all of the float values in afterFourier to 8 bit values, so you may want to do some scaling/rounding to the array before you do this, depending on your application.

like image 172
ford Avatar answered Oct 10 '22 16:10

ford