Can't access camera using OpenCV.

This is the error I’m getting:

VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/nvidia/build-opencv/opencv/modules/imgproc/src/color.cpp, line 11048
Traceback (most recent call last):
File “”, line 14, in
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: /home/nvidia/build-opencv/opencv/modules/imgproc/src/color.cpp:11048: error: (-215) scn == 3 || scn == 4 in function cvtColor

Can anyone help me with this? Thanks.

Probably your video capture failed to open and get frame.
I have no idea what makes before line 14… you may also say which camera you are trying to use…If it is TX2 devkit onboard camera, then you need an opencv version with gstreamer support enabled.
If it is a USB camera, it may work with v4l2 interface, but it depends on the formats your camera can output and what your opencv version expects (old opencv versions only supported gray8 or BGR8 formats). Since onboard camera is /dev/video0, usually first usb camera would have /dev/video1 and with opencv you would use VideoCapture(1).