Hi, I am using Nvidia Jetson Nano and Raspberry Pi V2.1 Camera for color detection via Python and OpenCV. However, the codes that worked on my computer do not work on Jetson Nano and I keep getting errors. The camera is working, I checked it. Also, Jetson Nano is in operation but camera does not opened. I could not get the problem.
Here is my code:
import cv2
print(cv2.version)
dispW=320
dispH=240
flip=2
camSet=‘nvarguscamerasrc ! video/x-raw(memory:NVMM), width=3264, height=2464, format=NV12, framerate=21/1 ! nvvidconv flip-method=’+str(flip)+’ ! video/x-raw, width=‘+str(dispW)+’, height=‘+str(dispH)+’, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink’
cam=cv2.VideoCapture(camSet)
lower_red = (147,46,91)
upper_red = (180,255,255)
while True:
ret, frame=cam.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, lower_red,upper_red)
final_frame = cv2.bitwise_and(frame,frame, mask = mask)
cv2.imshow("Frame", frame)
cv2.imshow("Mask", mask)
cv2.imshow("Final", final_frame)
if cv2.waitKey(1) ==ord("q"):
break
cam.release()
cv2.destroyAllWindows()
And here is the error:
3.2.0
OpenCV Error: Assertion failed ((scn== 3 || scn == 4) && (depth == CV_8U || depth == CV_32F)) in cvtColor, file /build/opencv-XDqSFW/opencv 3.2.0+dfsg/modules/imgproc/src/color.cpp, line 9815 Traceback (most recent call last):
File “red.py”, line 15, in
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
cv2.error: /build/opencv-XDqSFW/opencv 3.2.0+dfsg/modules/imgproc/src/color.cpp:9815: error: (-215) (scn== 3 || scn== 4) && (depth == CV_8U || depth == CV_32F) in function cvtColor