简体   繁体   中英

convert from imageproc module image of rasbperry pi into ( numpy array or cvmat )

imageproc module in rasbperry pi is very efficient but i couldn't use opencv with it due to the different type of image related to imageproc module.

So , i seek for a method to enable using opencv of image type( cvmat for cv , numpyarray for cv2 , .. ) with the rasbperry pi imageproc module Thanks in advance

You will first have to convert the imgproc output to a numpy.array . After that you can use the array with cv2 almost directly.

If we assume you have your imgproc image in img , then:

import numpy

img_array = numpy.array([ [ img[x,y] for x in range(img.width) ] for y in range(img.height) ] , dtype='uint8')

Unfortunately, there are no faster data access methods in imgproc , you will have to do it one-by-one. But after this slowish looping you can use img_array directly with cv2 .


If this crashes (it shouldn't) with a segfault (it really shouldn't) something goes badly wrong probably in imgproc . The best guess is that img[x,y] points to outside of the image created by imgproc . To debug this, let's split the command into more palatable parts.

# 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

Where does this crash? Note that the print statement is not entirely reliable with segfaults on all platforms, but it indicates that the code has run at least that far.

If the code crashes when accessing img dimensions or pixels, the problem may be in the image capture code. If you show a minimal example in the question, the problem is easier to debug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM