Soc ninja title

Raspberry pi 3 with Opencv and serial connection with a microcontroller

Components

Components list
Qty. Component Provider Total Price
1 Raspberry Pi 3 Model B exp-tech 55,68 €
1 Raspberry Pi 3 Case exp-tech 11,25 €
1 2.5A 5V Power Supply exp-tech 9,99 €
1 usb camera with mjpeg codec
1 any HDMI TV

Download the last Raspbian Jessie Little

https://www.raspberrypi.org/downloads/raspbian/

  • Unzip the image: 
  • Identify your sdcard:  $ sudo fdisk -l
  • copy the image to tour sdcard

$ sudo dd bs=1m if=<debian-image>.img of=/dev/<sdcard-disk> 

TRICK: If you want to monitor the progress of dd use:

$ sudo su -
# pv <debian-image>.img | dd bs=1m of=/dev/
<sdcard-disk>

Configure raspbian

sudo raspi-config
1 Expand Filesystem Ensures that all of the SD card storage is available to the OS
2 Change User Password Change password for the default user (pi)
4 Internationalisation Options > I3 Change keyboard layout (Select first opiton as default)
8 Advanced Options> SSH Enable remote command line access to your Pi using SSH.

Configure hostname:

$  sudo vim /etc/hostname 

#just as example
raspi_01
$  sudo vim /etc/hosts
127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

127.0.1.1       raspi_01

Setup multiple wifi networks with static IPs

Then disable the DHCP client daemon and switch to standard Debian networking:

$ sudo systemctl disable dhcpcd 
$ sudo systemctl enable networking
Configure static or dhcp network adddresses on your Pi in /etc/network/interfaces
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

# iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

# example of static configuration
iface work inet static
address 192.168.1.21
gateway 192.168.1.1
netmask 255.255.255.0
dns-nameservers 192.168.1.1
dns-nameservers 8.8.8.8

# example of dhcp configuration
iface home inet dhcp

# allow-hotplug wlan1
# iface wlan1 inet manual
#     wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Configure network wifi sids and passwords /etc/wpa_supplicant/wpa_supplicant.conf

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="WORK_SID"
    #psk="work_password"
    psk=a8d5e28b72da4ecaf0b870ab35fb212f4c69733dd7ac5089c7a03053cdb89601
}

network={
    ssid="HOME_SID"
    #psk="home_password"
    psk=ac870d497fca07c5e7146c09e4659150fdf81011fe18e5108b21b74304a340c8
}

You can use your unencripted password in psk section or use wpa_passphrase to generate the network configuration:

$ wpa_passphrase HOME_SID
# reading passphrase from stdin
home_password  
network={
    ssid="HOME_SID"
    #psk="home_password"
    psk=ac870d497fca07c5e7146c09e4659150fdf81011fe18e5108b21b74304a340c8
}

Install python-opencv and check the camera

Install python-opencv:

$ sudo apt-get update
$ sudo apt-get install python-opencv

List devices:

$ v4l2-ctl --list-devices
HD Webcam C615 (usb-3f980000.usb-1.4):
    /dev/video0

Check the current video mode for your USB webcam:

$ v4l2-ctl --all
.....
Video input : 0 (Camera 1: ok)
Format Video Capture:
    Width/Height  : 640/480
    Pixel Format  : 'YUYV'
....
    Frames per second: 30.000 (30/1)
...

Check the available video modes for your USB webcam :

$ v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUYV 4:2:2

    Index       : 1
    Type        : Video Capture
    Pixel Format: 'MJPG' (compressed)
    Name        : Motion-JPEG

$ v4l2-ctl --list-formats-ext
....
    Pixel Format: 'YUYV'
    Name        : YUYV 4:2:2
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
....
        Size: Discrete 160x120
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.042s (24.000 fps
....
    Pixel Format: 'MJPG' (compressed)
    Name        : Motion-JPEG
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
....

Capturing video with v4l2 with libv4l support to convert any image format to RGB or YUV420

$ sudo apt-get install libv4l-dev python-dev
$ git clone https://github.com/gebart/python-v4l2capture.git
$ cd python-v4l2capture
$ ./setup.py build
$ sudo ./setup.py install

Download opencv_capture_v4l2.py from:

https://gist.github.com/royshil/0f674c96281b686a9a62




If you found anything useful enough and you want to thank us for that, please consider donating to people who need it, like the NGO OXFAM. Thank you !


Comments

Comments are manually approved. Just be a bit patient :-)

There are currently no comments

New Comment

required

required (not published)

optional

Recent Tweets