was successfully added to your cart.



Accessing the Raspberry Pi Camera with OpenCV and Python

By | OpenCV, Raspberry Pi

If you have never installed OpenCV on your Raspberry Pi, please checkout this post first.

Enable Camera

sudo raspi-config

Install PiCamera

$ cd ~/.virtualenvs/cv/bin/
$ source activate
$ pip install "picamera[array]"

Accessing a single image of your Raspberry Pi using Python and OpenCV.

# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
rawCapture = PiRGBArray(camera)
# allow the camera to warmup
# grab an image from the camera
camera.capture(rawCapture, format="bgr")
image = rawCapture.array
# display the image on screen and wait for a keypress
cv2.imshow("Image", image)

Test the code

$ python test_image.py

Accessing the video stream of your Raspberry Pi using Python and OpenCV.

# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))
# allow the camera to warmup
# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
    # grab the raw NumPy array representing the image, then initialize the timestamp
    # and occupied/unoccupied text
    image = frame.array
    # show the frame
    cv2.imshow("Frame", image)
    key = cv2.waitKey(1) & 0xFF
    # clear the stream in preparation for the next frame
    # if the `q` key was pressed, break from the loop
    if key == ord("q"):

Test the code

$ python test_video.py


Using Shell Script to install OpenCV 3.x on Raspberry Pi Running Raspbian

By | Raspberry Pi
#!/usr/bin/env bash




install_build_dependencies() {
    local build_packages="build-essential git cmake pkg-config"
    local image_io_packages="libjpeg-dev libtiff5-dev libjasper-dev \
    local video_io_packages="libavcodec-dev libavformat-dev \
                             libswscale-dev libv4l-dev \
                             libxvidcore-dev libx264-dev"
    local gtk_packages="libgtk2.0-dev"
    local matrix_packages="libatlas-base-dev gfortran"
    local python_dev_packages="python2.7-dev python3-dev python-pip python3-pip"

    sudo apt-get install -y $build_packages $image_io_packages $gtk_packages \
                       $video_io_packages $matrix_packages $python_dev_packages

install_global_python_dependencies() {
    sudo pip install virtualenv virtualenvwrapper

install_local_python_dependences() {
    pip install numpy

download_packages() {
    wget -c -O "${OPENCV_PACKAGE_NAME}.zip" "$OPENCV_URL"

unpack_packages() {
    # unzip args:
    # -q = quiet
    # -n = never overwrite existing files
    unzip -q -n "${OPENCV_PACKAGE_NAME}.zip"
    unzip -q -n "${OPENCV_CONTRIB_PACKAGE_NAME}.zip"

setup_virtualenv() {
    export WORKON_HOME="$HOME/.virtualenvs"
    source /usr/local/bin/virtualenvwrapper.sh
    mkvirtualenv -p python3 cv
    workon cv

build() {
          -D BUILD_EXAMPLES=ON \
    make ${MAKEFLAGS}

install() {
    sudo make install
    sudo ldconfig

log() {
    local msg="$1"; shift
    local _color_bold_yellow='\e[1;33m'
    local _color_reset='\e[0m'
    echo -e "\[${_color_bold_yellow}\]${msg}\[${_color_reset}\]"

main() {
    log "Installing build dependencies..."
    log "Downloading OpenCV packages..."
    log "Unpacking OpenCV packages..."
    log "Installing global python deps..."
    log "Setting up local python environment..."
    log "Building OpenCV..."

    mkdir build
    cd build

    echo "Installing OpenCV..."



Install OpenCV 3 on Raspberry Pi Raspbian

By | Raspberry Pi

Let’s release some more space on your SD card first.

$ sudo apt-get purge wolfram-engine
$ sudo apt-get purge libreoffice*
$ sudo apt-get clean
$ sudo apt-get autoremove

Almost 700MB space will be cleaned up when the unnecessary applications purged.

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo rpi-update
$ sudo reboot

Install dependencies

$ sudo apt-get update && sudo apt-get upgrade
$ 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 libcanberra-gtk*
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install python2.7-dev python3-dev



Within the Python virtual environment, please do remember there is no sudo before cmake command. The cmake result should be like the one down below if you are using Python 3.5. Pay attention to path value of numpy.

Before you start the compile I would suggest increasing your swap space. This will enable you to compile OpenCV with all four cores of the Raspberry Pi without the compile hanging due to memory exhausting.

Open up your /etc/dphys-swapfile file and then edit the CONF_SWAPSIZE variable:

# set size to absolute value, leaving empty (default) then uses computed value
#   you most likely don't want this, unless you have an special disk situation

If you do not perform this step it’s very likely that your Pi will hang.

From there, restart the swap service:

$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start
$ make -j4
$ sudo make install
$ sudo ldconfig

Don’t forget to go back to your /etc/dphys-swapfile file and:

Restart the swap service.

If you compiled OpenCV for Python 3, you need to issue the following commands to sym-link the cv2.so bindings into your cv virtual environment:

$ cd /usr/local/lib/python3.5/site-packages/
$ sudo mv cv2.cpython-35m-arm-linux-gnueabihf.so cv2.so
$ cd ~/.virtualenvs/cv/lib/python3.5/site-packages/
$ ln -s /usr/local/lib/python3.5/site-packages/cv2.so cv2.so

Keep in mind that the exact paths will need to be updated depending if you are using Python 3.4, Python 3.5, Python 3.6, etc.
If you instead compiled OpenCV for Python 2.7, you can use these commands to sym-link your cv2.so file into the cv virtual environment:

$ cd ~/.virtualenvs/cv/lib/python2.7/site-packages/
$ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so

Testing your optimized OpenCV + Raspberry Pi install

$ cd ~/.virtualenvs/cv/bin/
$ source activate
$ python
>>> import cv2
>>> cv2.__version__


How to change from default to alternative Python version on Raspberry Pi Raspbian

By | Raspberry Pi
$ ls /usr/bin/python*

To check what is your default python version execute:

$ python --version
Python 2.7.13

Change python version system-wide

To change python version system-wide we can use update-alternatives command. Logged in as a root user, first list all available python alternatives:

# update-alternatives --list python
update-alternatives: error: no alternatives for python

The above error message means that no python alternatives has been recognized by update-alternatives command. For this reason we need to update our alternatives table and include both python2.7 and python3.5:

# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
# update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python (python) in auto mode

The –install option take multiple arguments from which it will be able to create a symbolic link. The last argument specified it priority means, if no manual alternative selection is made the alternative with the highest priority number will be set. In our case we have set a priority 2 for /usr/bin/python3.4 and as a result the /usr/bin/python3.4 was set as default python version automatically by update-alternatives command.

# python --version
Python 3.5


PTN3460 Development Notes

By | Displayport, LVDS

The external EEPROM only stores one EDID (0x00 – 0x7F) and configuration registers (0x80 – 0xFF).

If external EEPROM is used (DEV_CFG pin = high) in application, then firmware will read EDID from external EEPROM data address 0x00-0x7F to overwrite the EDID 0 in SRAM , and read configuration registers from external EEPROM data address 0x80-0xFF to overwrite configuration registers in SRAM during power up (firmware initialization) phase.

You need to set configuration 0x84 (EPROM data address 0x84) = 0x01, so that the EDID 0 (external EEPROM 0x00 – 0x7F) will be used to send to the DP source (PC).

So in short, if you want to use external EEPROM in application, than you need to set configuration register 0x84 = 0x01 and write EDID in the EEPROM data address 0x00-0x7F, so the EDID will be sent to the DP source (PC).

ASUS Thinker Board

By | Development Environment

  • Quad core 1.8GHz ARM Cortex-A17 CPU
  • 2GB Dual channel LPDDR3 memory
  • Gigabit LAN and Bluetooth 4.0 + EDR connectivity
  • 802.11 b/g/n Wi-Fi
  • 4x USB 2.0 ports
  • 40-pin Internal header with 28 GPIO pins
  • Contact points for PWM and S/PDIF signals
  • 1x 3.5mm Audio jack connection
  • CSI port for camera connection
  • DSI port supporting HD resolution
  • 1x HDMI 2.0 port to support 4K resolution
  • Micro SD port supports UHS-I
  • Supports Debian OS with KODI
  • Power supply: 5V/ 2A Micro USB (not included)

Install Java 1.8 on Mac OS El Capitan

By | Development Environment

Here’s a few notes on what it took to install Java12 on the latest El Capitan OSX: 10.11.1.

This seems to be the best way to set this up.

Install Cask7:

brew update
brew install caskroom/cask/brew-cask

Install jenv:

brew install jenv
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(jenv init -)"' >> ~/.zshrc

Install latest Java:

brew cask install java

The next is figure out where is the new JDK installed location, normally in the /Library/Java/JavaVirtualMachines/jdk******/Contents/Home/. The JDK version might be different.

jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/

When you execute the jenv add command, might return an error message shows:

ln: /Users/XXX/.jenv/versions/oracle64- No such file or directory

Then we just create the missing folder as the location above:

mkdir /Users/XXX/.jenv/versions/oracle64-

Check the new Java version:

java -version

That works.