rasbperry pi中的imageproc模块效率非常高,但由于与imageproc模块相关的图像类型不同,我无法使用opencv 。将rasbperry pi的imageproc模块图像转换为(numpy array或cvmat)
所以,我寻求一种方法,使预先使用图像类型(用于与CvMat CV,numpyarray为CV2,..)的OpenCV的与rasbperry PI imageproc模块 感谢
rasbperry pi中的imageproc模块效率非常高,但由于与imageproc模块相关的图像类型不同,我无法使用opencv 。将rasbperry pi的imageproc模块图像转换为(numpy array或cvmat)
所以,我寻求一种方法,使预先使用图像类型(用于与CvMat CV,numpyarray为CV2,..)的OpenCV的与rasbperry PI imageproc模块 感谢
,您必须首先转换imgproc
输出到numpy.array
。之后,您几乎可以直接使用cv2
这个阵列。
如果我们假设你有你的imgproc
图像中img
,则:
import numpy
img_array = numpy.array([ [ img[x,y] for x in range(img.width) ] for y in range(img.height) ] , dtype='uint8')
不幸的是,在imgproc
没有更快的数据访问方法,你将有一个接一个做。但是,在循环速度较慢之后,您可以直接使用img_array
与cv2
。
如果崩溃(它不应该)有段错误(这实在不应该)某事很可能在imgproc
严重错误。最好的猜测是img[x,y]
指向由imgproc
创建的图像的外部。为了调试,我们将命令分成更多可口的部分。
# dimensions ok?
w = img.width
h = img.height
print w,h
# can we fetch pixels at the extremes?
upperleft = img[0,0]
lowerright = img[w-1, h-1]
print upperleft, lowerright
# the loop without conversion to array
img_l = [ [ img[x,y] for x in range(w) ] for y in range(h) ]
print len(img_l)
# convert the image into an array
img_array = numpy.array(img_l, dtype='uint8')
print img_array.shape
哪里此崩溃?请注意,在所有平台上,print
语句对于段错误并不完全可靠,但它表明代码已运行至少那么远。
如果代码在访问img
尺寸或像素时崩溃,则问题可能出现在图像捕获代码中。如果您在问题中显示了一个最简单的示例,则该问题更易于调试。
我会尝试这种方法 非常感谢你 –
这似乎没有错误,但给“分段错误” –
这很有趣。它在哪里崩溃?如果从代码中删除上面的行('img_array = ...'),它是否仍然崩溃?您是否验证了OpenCV的工作原理?如果你编辑你的问题,它会有帮助,以便它有一个崩溃代码的最小例子。 – DrV