在OpenCV Python包装器中是否有与OpenCV 2中Mat的convertTo方法执行相同操作的函数?
我基本上想在Python中调用此函数。
out.convertTo( out, CV_32F, 1.0/255, 0 );
out是一张灰度图像。
我已经使用了cv.ConvertScale函数,并将dst参数保持为CV_32FC1类型,但我尝试尽可能使我的Python代码符合cv2规范。有什么线索吗?
res = np.float32(out)
扩展性方面,你需要单独处理:
res = res*scaling_factor
cv2.convertScaleAbs(image, result, alpha, beta)
其中alpha是比例因子,beta是偏移值。 OpenCV文档中有更多详细信息。
img2 = np.int16(img1) # convert to signed 16 bit integer to allow overflow
img2 = scale_factor*img2 # apply scale factor
img2 = clip(img2, 0, 255) # force all values to be between 0 and 255
# after clip img2 is effectively unsigned 8 bit, but make it explicit:
img2 = np.uint8(img2)
clip()
有一个注意事项:您必须拥有足够大的数组数据类型来容纳首先发生的溢出。因此,我更喜欢在可能的情况下使用OpenCV函数,例如convertScaleAbs。 - bfris