使用cv2和numpy的奇数图像 [英] odd image using cv2 and numpy

查看:174
本文介绍了使用cv2和numpy的奇数图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下代码:

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)

,我得到以下结果: 该图像是高度为720p,宽度为1280的RGB图像. 有任何想法如何解决吗?

and I get this result: the image is RGB image with height of 720p and width of 1280. Any Ideas how to solve it?

编辑:我从相机接收分辨率为720x1280的图像.该图像是彩色图像.我从中读取字节的文件raw_image包含命令的输出:

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

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?

推荐答案

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

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

我推断您的gst东西是不快乐" .

您共享的图片包含以下内容:

The image you have shared contains this:

我像终端一样使用 ImageMagick 将其转换为JPEG:

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

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

我再次推断出您的gst东西是不开心" .

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

这篇关于使用cv2和numpy的奇数图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆