简体   繁体   中英

odd image using cv2 and numpy

I am running the following code:

import cv2
import numpy
f = open("raw_image",'rb')
raw_image = f.read(720 * 1280 * 3)
image = numpy.fromstring(raw_image, dtype='uint8')
image = image.reshape((720, 1280, 3))
cv2.imshow('Image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.waitKey(1)

and I get this result: 在此处输入图片说明 the image is RGB image with height of 720p and width of 1280. Any Ideas how to solve it?

EDIT : I receive images from a camera with resolution of 720x1280. The image is a colored image. The file raw_image , which I read the bytes from, contains the output from the command:

gst-launch-1.0 fdsrc ! h264parse ! avdec_h264 ! filesink location=/dev/stdout

As you can see, the received image is malformed, and I dont know how to fix it.

EDIT2: this is the raw image: https://drive.google.com/file/d/1hPRUEVNFiKmiUFbzksUlzzC04teml4hw/view?usp=sharing

EDIT3: after running the code (NOTE: I am displaying only the first 720*1280 bytes):

raw_image = f.read(720 * 1280 * 3)
raw_image=raw_image[:720 * 1280]
image=numpy.frombuffer(raw_image,dtype='uint8')
image = image.reshape((720,1280))
cv2.imshow('Image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.waitKey(1)

I got this result: 在此处输入图片说明 When I move some of the left part to the right, by adding the line:

image=numpy.concatenate((image[:,141:],image[:,:141]),axis=1)

I got a fine image: 在此处输入图片说明

can it help solving the mystery?

If you generate a Red-Blue gradient like this with ImageMagick in the Terminal, you will see that your code works fine:

convert -size 1280x720 gradient:red-blue -depth 8 rgb:raw_image

在此处输入图片说明


I deduce your gst stuff is "unhappy" .


The image you have shared contains this:

在此处输入图片说明

I converted it to a JPEG using ImageMagick like the in the Terminal:

convert -size 1280x720 -depth 8 rgb:raw_image.dms result.jpg

I deduce again that your gst stuff is "unhappy" .

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