was successfully added to your cart.

How to compile Oculus Rift DK2 Firmware

By | STM32

DK2 Firmware
============

Licenses
——–

The Oculus firmware is licensed under the BSD-style license at
https://github.com/fbsamples/RiftDK2/blob/master/Headset/Firmware/LICENSE

We also provide for the Oculus firmware an additional grant of patent rights at
https://github.com/fbsamples/RiftDK2/blob/master/Headset/Firmware/PATENTS

The firmware incorporates or references materials of third parties that are
subject to other licenses.  Please see the individual headers on each file to
determine which license applies. For ease of reference, headers that include
the link http://www.st.com/software_license_agreement_liberty_v2 refer to the
license reproduced in en.ultimate-liberty-v2.txt.

External Libraries
——————

The ARM CMSIS library is not included, but can be downloaded from:
https://github.com/ARM-software/CMSIS/tree/master/CMSIS

The firmware was originally developed with CMSIS 3.01

This should be placed in lib/CMSIS

Building DK2 Firmware
———————

Building DK2 firmware currently requires IAR EWARM. You can get a 30-day trial
here: http://supp.iar.com/Download/SW/?item=EWARM-EVAL

Programming DK2 Firmware to a Board
———————————–

### Updating an already programmed board

You can update a DK2 over USB using the Oculus Configuration Utility:
https://product-guides.oculus.com/en-us/documentation/dk2/latest/tasks/ug-tray-start-firmware/

In this case, you should use the most recent DK2.bin available for your board.

* Rev 3 (GDC units): prj/REV3/Exe/DK2.bin
* Rev 3.3 (Pilot run and production units): prj/REV3_3/Exe/DK2.bin

### Programming to a blank board

For a blank board, you’ll need to program it over the SWD header using an ST-Link programmer.

In this case, you’ll need the ST-Link utility and DK2Bootloader.bin

* Rev 3 (GDC units): bootloader/prj/REV3/Exe/DK2.bin
* Rev 3.3 (Pilot run and production units): bootloader/prj/REV3_3/Exe/DK2.bin

How to access Tensorflow tensorflow.org

By | Others

Modify host file

#TensorFlow start 
64.233.188.121 www.tensorflow.org 
#TensorFlow end

Clean your DNS Cache

macOS Sierra 10.12.0

sudo killall -HUP mDNSResponder

OSX 10.11.0

sudo killall -HUP mDNSResponder

OSX 10.10.4

sudo killall -HUP mDNSResponder

Windows

ipconfig /flushdns

Linux(depending on what you’re running)

/etc/init.d/named restart
/etc/init.d/nscd restart

 

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
time.sleep(0.1)
 
# 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)
cv2.waitKey(0)

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
time.sleep(0.1)
 
# 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
    rawCapture.truncate(0)
 
    # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break

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

OPENCV_VERSION="3.1.0"

OPENCV_URL="https://github.com/Itseez/opencv/archive/${OPENCV_VERSION}.zip"
OPENCV_PACKAGE_NAME="opencv-${OPENCV_VERSION}"
OPENCV_CONTRIB_URL="https://github.com/Itseez/opencv_contrib/archive/${OPENCV_VERSION}.zip"
OPENCV_CONTRIB_PACKAGE_NAME="opencv_contrib-${OPENCV_VERSION}"

PREFIX="${PREFIX:-/usr/local}"
MAKEFLAGS="${MAKEFLAGS:--j 4}"

install_build_dependencies() {
    local build_packages="build-essential git cmake pkg-config"
    local image_io_packages="libjpeg-dev libtiff5-dev libjasper-dev \
                             libpng12-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"
    wget -c -O "${OPENCV_CONTRIB_PACKAGE_NAME}.zip" "$OPENCV_CONTRIB_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
    install_local_python_dependences
}

build() {
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
          -D CMAKE_INSTALL_PREFIX="$PREFIX" \
          -D INSTALL_C_EXMAPLES=ON \
          -D INSTALL_PYTHON_EXAMPLES=ON \
          -D OPENCV_EXTRA_MODULES_PATH="$HOME/$OPENCV_CONTRIB_PACKAGE_NAME/modules" \
          -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..."
    install_build_dependencies
    log "Downloading OpenCV packages..."
    download_packages
    log "Unpacking OpenCV packages..."
    unpack_packages
    log "Installing global python deps..."
    install_global_python_dependencies
    log "Setting up local python environment..."
    setup_virtualenv
    log "Building OpenCV..."

    cd "$OPENCV_PACKAGE_NAME"
    mkdir build
    cd build

    build
    echo "Installing OpenCV..."
    install
}

main

 

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

 

$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_EXAMPLES=ON -D ENABLE_NEON=ON -D ENABLE_VFPV3=ON -D BUILD_TESTS=OFF -D ENABLE_PRECOMPILED_HEADERS=OFF -D OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib-3.1.0/modules ..

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
# CONF_SWAPSIZE=100
CONF_SWAPSIZE=1024

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:

Reset CONF_SWAPSIZE to 100MB.
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__
'3.3.0'
>>>

 

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