如何解决尝试使用 OpenCV - TypeError:并非所有参数都在字符串格式化期间转换
我正在关注 YouTube 视频,开始使用我的 Jetson Nano 上的摄像头。这是链接:https://www.youtube.com/watch?v=GQ3drRllX3I 但是,当我启动 python 代码时,我一直面临错误 - TypeError:不是所有参数都在字符串格式化期间转换。代码如下。我已经安装了 Cython 和 Numpy。
# MIT License
# copyright (c) 2019 JetsonHacks
# See license
# Using a CSI camera (such as the RaspBerry Pi Version 2) connected to a
# NVIDIA Jetson Nano Developer Kit using OpenCV
# Drivers for the camera and OpenCV are included in the base image
import cv2
# gstreamer_pipeline returns a GStreamer pipeline for capturing from the CSI camera
# Defaults to 1280x720 @ 60fps
# Flip the image by setting the flip_method (most common values: 0 and 2)
# display_width and display_height determine the size of the window on the screen
def gstreamer_pipeline(
capture_width=1280,capture_height=720,display_width=1280,display_height=720,framerate=60,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,format=(string)BGRx ! "
"videoconvert ! "
"video/x-raw,format=(string)BGR ! appsink"
% (
capture_width,capture_height,framerate,flip_method,display_width,display_height,)
)
def show_camera():
# To flip the image,modify the flip_method parameter (0 and 2 are the most common)
print(gstreamer_pipeline(flip_method=0))
cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0),cv2.CAP_GSTREAMER)
if cap.isOpened():
window_handle = cv2.namedWindow("CSI Camera",cv2.WINDOW_AUTOSIZE)
# Window
while cv2.getwindowProperty("CSI Camera",0) >= 0:
ret_val,img = cap.read()
cv2.imshow("CSI Camera",img)
# This also acts as
keyCode = cv2.waitKey(30) & 0xFF
# Stop the program on the ESC key
if keyCode == 27:
break
cap.release()
cv2.destroyAllWindows()
else:
print("Unable to open camera")
if __name__ == "__main__":
show_camera()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。