为什么 gstreamer 捕获图像不正确?
Why does gstreamer capture image incorrectly?
您好,
我有一个带有 Raspberry Pi v2.1 相机的 Jetson Nano 设备,并使用 gstreamer 和 OpenCV 来捕捉图像。不过,我认为这个问题最好保留在这里,因为我主要认为这是一个软件问题。
重点是:我使用以下 Python-script 来捕获我的图像:
import cv2
import numpy as np
import matplotlib.pyplot as plt
from scipy.misc import imshow
def gstreamer_pipeline (capture_width=3280, capture_height=2464, display_width=1280, display_height=720, framerate=21, flip_method=0) :
return ('nvarguscamerasrc ! '
'video/x-raw(memory:NVMM), '
'width=(int)%d, height=(int)%d, '
'format=(string)NV12, framerate=(fraction)%d/1 ! '
'nvvidconv flip-method=%d ! '
'video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! '
'videoconvert ! '
'video/x-raw, format=(string)BGR ! appsink' % (capture_width,capture_height,framerate,flip_method,display_width,display_height))
if __name__ == '__main__':
cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
if cap.isOpened():
ret_val, img = cap.read()
img = np.flipud(img)
img = np.fliplr(img)
imshow(img)
cv2.imwrite("test.jpg", img)
else:
print("Unable to open camera.")
我的问题是我不确定它是否正确捕捉颜色值。当我使用 SciPy 中的 imshow(img)
显示我刚刚拍摄的图像时,它看起来像这样:
(I do not have enough reputation to insert it, so please see this link)
这很奇怪,因为它的色调很蓝。我用cv2.imwrite("test.jpg", img)
保存后,又正常了:(Here the another image)
我不知道我是否在 gstreamer-pipeline 中定义了错误或者其他什么可能导致错误。正确捕获颜色对我的程序很重要,因为我不想保存图像然后加载它只是为了获得正确的颜色(在速度和 CPU-power 方面不好),我会非常很高兴有人能帮助我。
提前感谢您的回答!
正如 HansHirse 所说,您的颜色 space 是错误的。
您可以更改 gstreamer 管道以输出 RGB
format=(string)RGB
或者在 oopencv 中从 BGR 转换为 RGB
im_rgb = cv2.cvtColor(im_cv, cv2.COLOR_BGR2RGB)
您好,
我有一个带有 Raspberry Pi v2.1 相机的 Jetson Nano 设备,并使用 gstreamer 和 OpenCV 来捕捉图像。不过,我认为这个问题最好保留在这里,因为我主要认为这是一个软件问题。 重点是:我使用以下 Python-script 来捕获我的图像:
import cv2
import numpy as np
import matplotlib.pyplot as plt
from scipy.misc import imshow
def gstreamer_pipeline (capture_width=3280, capture_height=2464, display_width=1280, display_height=720, framerate=21, flip_method=0) :
return ('nvarguscamerasrc ! '
'video/x-raw(memory:NVMM), '
'width=(int)%d, height=(int)%d, '
'format=(string)NV12, framerate=(fraction)%d/1 ! '
'nvvidconv flip-method=%d ! '
'video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! '
'videoconvert ! '
'video/x-raw, format=(string)BGR ! appsink' % (capture_width,capture_height,framerate,flip_method,display_width,display_height))
if __name__ == '__main__':
cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
if cap.isOpened():
ret_val, img = cap.read()
img = np.flipud(img)
img = np.fliplr(img)
imshow(img)
cv2.imwrite("test.jpg", img)
else:
print("Unable to open camera.")
我的问题是我不确定它是否正确捕捉颜色值。当我使用 SciPy 中的 imshow(img)
显示我刚刚拍摄的图像时,它看起来像这样:
(I do not have enough reputation to insert it, so please see this link)
这很奇怪,因为它的色调很蓝。我用cv2.imwrite("test.jpg", img)
保存后,又正常了:(Here the another image)
我不知道我是否在 gstreamer-pipeline 中定义了错误或者其他什么可能导致错误。正确捕获颜色对我的程序很重要,因为我不想保存图像然后加载它只是为了获得正确的颜色(在速度和 CPU-power 方面不好),我会非常很高兴有人能帮助我。
提前感谢您的回答!
正如 HansHirse 所说,您的颜色 space 是错误的。
您可以更改 gstreamer 管道以输出 RGB
format=(string)RGB
或者在 oopencv 中从 BGR 转换为 RGB
im_rgb = cv2.cvtColor(im_cv, cv2.COLOR_BGR2RGB)