简体   繁体   English

使用cv2和numpy的奇数图像

[英]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? 该图像是高度为720p,宽度为1280的RGB图像。有什么想法如何解决?

EDIT : I receive images from a camera with resolution of 720x1280. 编辑 :我从分辨率为720x1280的相机接收图像。 The image is a colored image. 该图像是彩色图像。 The file raw_image , which I read the bytes from, contains the output from the command: 我从中读取字节的文件raw_image包含命令的输出:

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 EDIT2:这是原始图像: 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): EDIT3:运行代码后(注意:我仅显示前720 * 1280字节):

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: 如果您在终端中使用ImageMagick生成像这样的红蓝色渐变,您将看到代码可以正常工作:

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

在此处输入图片说明


I deduce your gst stuff is "unhappy" . 我推断您的gst “不高兴”


The image you have shared contains this: 您共享的图像包含以下内容:

在此处输入图片说明

I converted it to a JPEG using ImageMagick like the in the Terminal: 我使用终端中的ImageMagick将其转换为JPEG:

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

I deduce again that your gst stuff is "unhappy" . 我再次推断出你的gst的东西是“不高兴”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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