Version 13 (modified by 3 months ago) ( diff ) | ,
---|
USB Web Cams
The 825gen2 has some support for USB cameras.
After plugging a Logitech USB webcam into the 825 from a terminal type dmesg.
card825gen2:~$ dmesg ... [ 7653.802688] usb 1-1.4: new high-speed USB device number 4 using xhci-hcd [ 7654.211992] usb 1-1.4: Found UVC 1.00 device <unnamed> (046d:0825) [ 7654.324569] input: UVC Camera (046d:0825) as /devices/platform/soc@0/38200000.usb/xhci-hcd.0.auto/usb1/1-1/1-1.4/1-1.4:1.0/input/input7 [ 7654.325132] usbcore: registered new interface driver uvcvideo [ 7655.880687] usb 1-1.4: set resolution quirk: cval->res = 384 [ 7655.881370] usbcore: registered new interface driver snd-usb-audio
This shows the webcam was detected, "registered new interface driver uvcvideo". Many webcams currently are UVC (USB Video Class) compliant. The 825gen2 has support for this.
Type lsmod to show loaded modules
card825gen2:~$ lsmod Module Size Used by snd_usb_audio 294912 0 snd_hwdep 20480 1 snd_usb_audio snd_usbmidi_lib 36864 1 snd_usb_audio uvcvideo 106496 0 algif_hash 20480 1 algif_skcipher 20480 1 af_alg 32768 6 algif_hash,algif_skcipher cardmnbdm 24576 0 rpmsg_ctrl 16384 0 …
The uvcvideo module was loaded automatically when the camera was plugged in and detected.
Capture still image
From the terminal type the following command to capture a still image from the camera.
card825gen2:~$ gst-launch-1.0 v4l2src device=/dev/video2 num-buffers=1 ! jpegenc ! filesink location=/tmp/test.jpg Setting pipeline to PAUSED ... Pipeline is live and does not need PREROLL ... Pipeline is PREROLLED ... Setting pipeline to PLAYING ... New clock: GstSystemClock Redistribute latency... Got EOS from element "pipeline0". Execution ended after 0:00:02.385972216 Setting pipeline to NULL ... Freeing pipeline ...
The file /tmp/test.jpg contains the image.
To capture an image from an app a system call could be used to perform the above command line. However, it is better to use the gstreamer library within the code. An example function to capture an image follows:
void WebCamCapture(const char* writePath) { char cmd[200]; GstElement* pipeline; GstBus* bus; GstMessage* msg; snprintf(cmd, sizeof(cmd), "v4l2src device=/dev/video2 num-buffers=1 ! jpegenc ! filesink location=%s", writePath); pipeline = gst_parse_launch(cmd, NULL); gst_element_set_state (pipeline, GST_STATE_PLAYING); /* Wait until error or EOS */ bus = gst_element_get_bus(pipeline); msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS)); if(msg != NULL) { gst_message_unref(msg); } gst_object_unref(bus); gst_element_set_state(pipeline, GST_STATE_NULL); gst_object_unref(pipeline); }
Display Live Vido
To display live video on the LCD display the following terminal command may be used:
card825gen2:~$ gst-launch-1.0 v4l2src device=/dev/video2 ! autovideosink
Following is an example function to display live video for the specified number of seconds:
void WebCamDisplayVideo(int seconds) { GstElement* pipeline; GstBus* bus; GstMessage* msg; const char* cmd = "v4l2src device=/dev/video2 ! autovideosink"; pipeline = gst_parse_launch(cmd, NULL); gst_element_set_state (pipeline, GST_STATE_PLAYING); /* Wait until error or EOS */ bus = gst_element_get_bus(pipeline); msg = gst_bus_timed_pop_filtered(bus, seconds * 1000 * GST_MSECOND, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS)); if(msg != NULL) { gst_message_unref(msg); } gst_object_unref(bus); gst_element_set_state(pipeline, GST_STATE_NULL); gst_object_unref(pipeline); }