The phyCORE-AM57x development kit supports many common USB WebCams via the Video4Linux driver which is included with the kernel. This guide walks through the basic usage of the v4l2-ctl utility in Linux to make changes to the Logitech C270 HD WebCam's saturation setting and how to use OpenCV to stream video feed to the LCD-018 display using Python.




Requirements 

ItemItem Number (Description) Link

Touch Screen Display

7" LCD-018 Touch Screen DisplayLCD-018

Logitech WebCam

Image result for logitech c270 hd webcam

C270 HDLogitech C270 HD WebCam

Verifying Default Settings

  • With your phyCORE-AM57x development kit powered on and booted into Linux, connect the WebCam to the USB3.0 port designated as USB1. You should see kernel messages indicating that the WebCam was detected similar to the below:

    Expected Output

    [ 1651.657000] usb 1-1: new high-speed USB device number 3 using xhci-hcd
    [ 1652.058998] usb 1-1: New USB device found, idVendor=046d, idProduct=0825, bcdDevice= 0.12
    [ 1652.067241] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=2
    [ 1652.074410] usb 1-1: SerialNumber: 7B1094E0
    [ 1652.105154] uvcvideo: Found UVC 1.00 device <unnamed> (046d:0825)
    [ 1652.223081] uvcvideo 1-1:1.0: Entity type for entity Extension 4 was not initialized!
    [ 1652.230981] uvcvideo 1-1:1.0: Entity type for entity Extension 6 was not initialized!
    [ 1652.240628] uvcvideo 1-1:1.0: Entity type for entity Extension 7 was not initialized!
    [ 1652.249368] uvcvideo 1-1:1.0: Entity type for entity Processing 2 was not initialized!
    [ 1652.258184] uvcvideo 1-1:1.0: Entity type for entity Extension 3 was not initialized!
    [ 1652.266056] uvcvideo 1-1:1.0: Entity type for entity Camera 1 was not initialized!
    [ 1652.275587] input: UVC Camera (046d:0825) as /devices/platform/44000000.ocp/48880000.omap_dwc3_1/48890000.usb/xhci-hcd.1.auto/usb1/1-1/1-1:1.0/input/input3
    [ 1653.688062] usb 1-1: set resolution quirk: cval->res = 384
    
    CODE
  • You will also notice that a new device /dev/video1 has appeared! 

    Target (Linux)

    ls /dev/video*
    CODE
  • You can see what settings are available for this WebCam with the following command: 

    Target (Linux)

    v4l2-ctl -d 1 --list-ctrls
    CODE

    Expected Output

    root@am57xx-phycore-kit:~# v4l2-ctl -d 1 --list-ctrls
                         brightness 0x00980900 (int)    : min=0 max=255 step=1 default=128 value=128
                           contrast 0x00980901 (int)    : min=0 max=255 step=1 default=32 value=32
                         saturation 0x00980902 (int)    : min=0 max=255 step=1 default=32 value=32
     white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                               gain 0x00980913 (int)    : min=0 max=255 step=1 default=64 value=64
               power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=2 value=2
          white_balance_temperature 0x0098091a (int)    : min=0 max=10000 step=10 default=4000 value=4000 flags=inactive
                          sharpness 0x0098091b (int)    : min=0 max=255 step=1 default=24 value=24
             backlight_compensation 0x0098091c (int)    : min=0 max=1 step=1 default=0 value=0
                      exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=3 value=3
                  exposure_absolute 0x009a0902 (int)    : min=1 max=10000 step=1 default=166 value=166 flags=inactive
             exposure_auto_priority 0x009a0903 (bool)   : default=0 value=1
    CODE

    Looks like everything is set to their default settings. Let's output the video feed to the display and see what we get.

Video on Display

  • Enter this command to open a file named videoFeed.py using the Vi Text Editor: 

    Target (Linux)

    vi ~/videoFeed.py
    CODE
  • Edit the contents of the new file to reflect the code below and save the file: 

    videoFeed.py

    import cv2
    
    cap = cv2.VideoCapture(1)
    
    try:
            while(True):
                    # Capture frame-by-frame
                    ret, frame = cap.read()
    
                    # Display the resulting frame
                    cv2.imshow('frame',frame)
                    cv2.waitKey(1)
    
    except KeyboardInterrupt:
            # When everything done, release the capture
            cap.release()
            cv2.destroyAllWindows()
    CODE

    The vi text editor begins in "Command Mode" and you must first hit the 'i' key in order to enter "Insert Mode". Using the arrow keys to navigate, make the necessary changes and then hit ESC to go back to "Command mode". Now enter ":wq" to write the file and quit.


    Pro Tip: Copy and Paste the above code! This will only work if you are in "Insert Mode" first. 

  • Once you have saved and closed the file, give this python script executable permissions: 

    Target (Linux)

    chmod +x ~/videoFeed.py
    CODE
  • Run the script: 

    Target (Linux)

    python3.5 ~/videoFeed.py
    CODE




    Enter Ctrl + C to stop the script. 

    Getting Fancy!

  • Now that we have an idea of what the default settings look like, lets drop the saturation to zero before checking the video feed again: 

    Target (Linux)

    v4l2-ctl -d 1 --set-ctrl=saturation=0
    python3.5 ~/videoFeed.py
    CODE

  • Try modifying the other settings in a similar way until you have your camera configured the way you like!