Hello;
In my use case, I'm using a Jetson Nano running Jupyter Lab. I ssh into the nano, and run Jupyter Lab on a web browser on the host machine, a laptop.
As such, I can't use cv2.imshow() to display the image. This only works when run locally.
Therefore, I've learned to use cv2.VideoCapture() to capture an image, but I'm having trouble encoding this image into the format required by ipywidgets.
Here is my code for capturing one camera frame:
import cv2
import ipywidgets
from IPython.display import display
from IPython.display import Image
gst_pipeline = "nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw ! jpegenc ! image/jpeg ! appsink"
camera = cv2.VideoCapture(gst_pipeline, cv2.CAP_GSTREAMER)
capture_state, captured_image = camera.read()
print(capture_state)
print(captured_image)
The output of this code produces these results:
capture_state = True
captured_image = [[255 216 255 ... 179 255 217]]
However, when I run the next code sequence, I get the following error:
error: OpenCV(4.1.1) /home/nvidia/host/build_opencv/nv_opencv/modules/imgcodecs/src/grfmt_base.cpp:145: error: (-10:Unknown error code -10) Raw image encoder error: Maximum supported image dimension is 65500 pixels in function 'throwOnEror'
This is the code I run, that produces that error:
encode_parameters = [int(cv2.IMWRITE_JPEG_QUALITY),20]
encode_state, encoded_image = bytes(cv2.imencode('.jpg', captured_image, encode_parameters))
In looking around the internt, it seems there is a need to do some sort of transform. In this code example, they are using a numpy array as shown here:
def __init__(self, *args, **kwargs):
super(Camera, self).__init__(*args, **kwargs)
if self.format == 'bgr8':
self.value = np.empty((self.height, self.width, 3), dtype=np.uint8)
self._running = False
I would really appreciate if someone could help me figure out what I need to do to get my "capture_image" into the right format so that I can do the encoding.
Once this step is good, I'll be able to view this image in an iPywidget - accomplishing my overall goal.
Can someone please help me?
Cheers!