Linux, OpenCV, Programming, Raspberry Pi

OpenCV 3.4.3 + Raspberry Pi 3B+

Follow these steps to install OpenCV 3.4.3 on a Raspberry Pi 3B+:

1) Install these dependencies:

$ sudo apt-get install build-essential cmake pkg-config
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
$ sudo apt-get install libgtk2.0-dev libgtk-3-dev
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install python2.7-dev python3-dev

2) Get OpenCV

$ wget https://github.com/opencv/opencv/archive/3.4.3.zip
$ unzip 3.4.3.zip
$ rm 3.4.3.zip
$ wget https://github.com/opencv/opencv_contrib/archive/3.4.3.zip
$ unzip 3.4.3.zip

3) Build & Install OpenCV
NOTE 1: In the cmake line there is a path to the opencv_contrib modules folder, please replace this path with the correct one for your system.

NOTE 2: The make step will take like 8-10 hours and it will crash several times due to low virtual memory. Luckily it can resume from where it crashes so I kept repeating the make command until it finished.

sudo apt-get install python-pip
pip install numpy
$ cd ~/opencv-3.4.3/
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/home/pi/Desktop/OpenCV/opencv_contrib-3.4.3/modules -D BUILD_EXAMPLES=ON ..
$ make -j4
$ sudo make install
$ sudo ldconfig

4) Confirm OpenCV installation

$ python
>>> import cv2
>>> cv2.__version__
'3.4.3'

5) Voila!

Advertisements
Raspberry Pi

Raspbian (PIXEL) with SDL2

UPDATE: SDL performance is very slow. I don’t think it has anything to do with the Raspberry Pi 1 that I’m using. It just can’t be that slow. I believe it has more to do with the fact the libsdl-dev package is not using OpenGL. It’s not compiled for that use. I might have to try build it from source….


Here are the ins

  1. Get Raspbian running
  2. Enable VNC and SSH
  3. sudo apt-get update
  4. sudo apt-get install libsdl2-dev
  5. Run your app

To run without desktop manager:

  1. Edit /home/pi/.config/lxsession/LXDE-pi/autostart
  2. Comment out all lines that start with @ with #
  3. Add your app and precede with @

Source: http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs-gui

To turn off the cursor:

  1. Edit /etc/lightdm/lightdm.conf
  2. Find the line ‘xserver_command’ under [SeatDefaults]
  3. Change it to ‘xserver_command = X -nocursor’

 

Raspberry Pi

SDL2 on Raspberry 1.0 running Minibian (FAILED)

UPDATE 2: I did the same thing on Raspbian and the compilation worked. See this.

UPDATE 1: This didn’t work, sorry guys. I couldn’t figure it out. Tried everything, running out of time…giving up…I’m going to try to make the game another way.


I have the very first Raspberry Pi, which I believe is a 1.0. I’m trying to make a game with it and I decided to use SDL. The goal is to run SDL without X, ie from console.

The first thing I needed was a lightweight distro for the RPi. I’m using Minibian because I’ve used it before and it works. Instructions for this are pretty simple:

  1. Download Minibian (https://minibianpi.wordpress.com/download/)
  2. Use Rufus to flash it to an SD Card
  3. Run the RPi and resize the partitions (https://minibianpi.wordpress.com/how-to/resize-sd/). Read the instructions carefully especially the part about aligning the partitions.
  4. Install nano
  5. If you need Wifi, install firmware-realtek (assuming you have a Realtek based dongle) and wpasupplicant. For more info visit https://minibianpi.wordpress.com/how-to/wifi/

Next step is to install SDL:

DON’T INSTALL using the package manager, it doesn’t work. You need to compile from scratch.

  1. Install these packages required for compiling SDL (not sure if the mesa libraries are required):
    apt-get install build-essential libfreeimage-dev libopenal-dev libpango1.0-dev libsndfile1-dev libudev-dev libasound2-dev libjpeg-dev libtiff5-dev libwebp-dev automake
    apt-get install libraspberrypi-dev raspberrypi-kernel-headers
    apt-get install libegl1-mesa libegl1-mesa-dev
  2. Get SDL2 (https://www.libsdl.org/release/SDL2-2.0.5.tar.gz)
    mkdir install && cd install
    wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz
    tar zxvf SDL2-2.0.5.tar.gz
    cd SDL2-2.0.5
  3. Configure and build
    ./configure --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11
    make
    make install
  4. FAIL!

 

 

 

Raspberry Pi

Raspbmc alternative? Try OpenELEC

Recently my Raspbmc box hasn’t been so great. I found that the Web interface was quite slow, the commands weren’t processed as quickly as they should be from the XBMC remote app on Android. And then there was the crashing 😦 I was sick of it so I decided to look for Raspbmc alternatives and I found OpenELEC. I don’t know too much about the internals of OpenELEC but what I can tell you is that it is some sort of lightweight linux distro which runs XBMC. It is much faster than Raspbmc and works nicely. It was really easy to setup, I just followed these instructions (http://wiki.openelec.tv/index.php?title=Installing_OpenELEC_on_Raspberry_Pi). I did have some issues with setting up the wifi but I believe that was more a problem with USB powered hub I was using.

Programming, Raspberry Pi

OpenGL ES on Raspberry Pi

When writing OpenGL ES programs on the Raspberry Pi for the first time, you may encounter these issues:

1) Shaders aren’t working properly; the colors don’t come out correctly.

My Fragment Shader code was this:

precision lowp float;
varying vec3 vv3colour;
void main() {
    gl_FragColor = vec4(vv3colour, 1.0);
}

My Vertex Shader code was this:

attribute vec4 av4position;
attribute vec3 av3colour;
uniform mat4 mvp;
varying vec3 vv3colour;
void main() {
    vv3colour = av3colour;
    gl_Position = mvp * av4position;
}

SOLUTION: In my case the EGL_ALPHA_SIZE was not set in the attribList when the call to eglChooseConfig was made. Once I set EGL_ALPHA_SIZE to 8, it worked!

2) You can see X through your application, ie, the background is transparent.

SOLUTION: change the glClearColor line to (0.0f, 0.0f, 0.0f, 1.0f). I don’t understand it but that worked for me.

Programming, Raspberry Pi

OpenGL ES on Raspberry Pi without X

Here’s the source link: http://benosteen.wordpress.com/2012/04/27/using-opengl-es-2-0-on-the-raspberry-pi-without-x-windows/

Here are my instructions to build the examples:

mkdir glus
cd glus
wget --no-check-certificate https://github.com/benosteen/opengles-book-samples/tarball/master
tar -xvzf master
cd benosteen-opengles-book-samples-186d0ab
cd Raspi

NOTE: the folder will start with “benosteen-opengles-book-samples…”

Create a new file:

sudo nano /etc/ld.so.conf.d/raspi-opengles-lib.conf

add this line to the file:

/opt/vc/lib

Save and exit.

sudo ldconfig

Edit the Makefile:

nano Makefile

add this line to the end of the line starting with INCDIR:

-I/opt/vc/include/interface/vmcs_host/linux

Save and exit.

make

Done!


Here are my instructions to run an example:

cd Chapter_2
cd Hello_Triangle
./CH02_Hello_triangle

Done!