【发布时间】:2019-10-25 12:08:20
【问题描述】:
您好,
我有一个带有 Raspberry Pi v2.1 摄像头的 Jetson Nano 设备,并使用 gstreamer 和 OpenCV 来捕捉图像。不过,我认为这个问题在这里会得到更好的保留,因为我主要认为这是一个软件问题。 关键是:我使用以下 Python 脚本来捕获我的图像:
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 能力方面不好),如果有人可以,我会很高兴帮帮我。
提前感谢您的回答!
【问题讨论】:
-
OpenCV 使用 BGR,而 scipy 使用 RGB 颜色排序。抓拍应该没问题。请注意,您是在运行时使用 BGR。
标签: python image opencv raspberry-pi gstreamer