【问题标题】:cv2.threshold() error (-210)cv2.threshold() 错误 (-210)
【发布时间】:2014-05-09 19:11:40
【问题描述】:

我是 Python 新手。

我想借助傅里叶变换来定义文本旋转。

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)

但是这段代码失败了:

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

为什么会导致“-210”错误?

【问题讨论】:

  • 这是完整的错误吗?我希望不是。但通常 fft 适用于浮点数据,而 cv2.threshold 想要 uchar
  • @berak:完全错误

标签: python opencv image-processing computer-vision


【解决方案1】:

OpenCV error codes 可以在types_c.h 中查找。

错误代码-210定义为:

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

因此,您需要先将图像强制转换为 uint8 数据类型,然后再将其传递给 cv2.threshold。这可以通过 numpy 使用 astype 方法来完成:

afterFourier = afterFourier.astype(np.uint8)

这会将afterFourier 中的所有浮点值截断为 8 位值,因此您可能需要在执行此操作之前对数组进行一些缩放/舍入,具体取决于您的应用程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 2021-11-15
    • 2011-09-07
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多