OpenCv

OpenCV is released under a BSD license and hence it’s free for both academic and commercial use. It has C++, C, Python and Java interfaces and supports Windows, Linux, Mac OS, iOS and Android. OpenCV was designed for computational efficiency and with a strong focus on real-time applications. Written in optimized C/C++, the library can take advantage of multi-core processing. Enabled with OpenCL, it can take advantage of the hardware acceleration of the underlying heterogeneous compute platform. Adopted all around the world, OpenCV has more than 47 thousand people of user community and estimated number of downloads exceeding 9 million. Usage ranges from interactive art, to mines inspection, stitching maps on the web or through advanced robotics. Homepage

Required Applications

root@edison:~# nano /etc/opkg/base-feeds.conf
src/gz all http://repo.opkg.net/edison/repo/all
src/gz edison http://repo.opkg.net/edison/repo/edison
src/gz core2-32 http://repo.opkg.net/edison/repo/core2-32

Opkg Installation

root@edison:~# opkg update
root@edison:~# opkg install python-dev
root@edison:~# opkg install opencv opencv-dev opencv-apps
root@edison:~# opkg install opencv-samples opencv-samples-dev
root@edison:~# opkg install libopencv-imgproc-dev
root@edison:~# opkg install http://repo.opkg.net/edison/repo/core2-32/python-numpy_1.7.0-r1_core2-32.ipk
root@edison:~# opkg install http://repo.opkg.net/edison/repo/core2-32/python-opencv_2.4.11+git0+2c9547e314-r0_core2-32.ipk
root@edison:~# pip install pip --upgrade
root@edison:~# pip install flask numpy

Apt-Get Installation

root@edison:~# apt-get update
root@edison:~# apt-get install git python-pip python-serial python-pyparsing
root@edison:~# apt-get install opencv opencv-samples opencv-apps
root@edison:~# apt-get install opencv-dev opencv-samples-dev 
root@edison:~# apt-get install libopencv-imgproc-dev
root@edison:~# apt-get install python-numpy python-opencv

Hello OpenCV, Face Recognition

root@edison:~# cd /home/root/
root@edison:~# mkdir opencv
root@edison:~# cd opencv/
root@edison:~/opencv# wget https://raw.githubusercontent.com/xe1gyq/core/master/configuration/haarcascade_frontalface_alt.xml
root@edison:~/opencv# nano facerecognition.py
import cv2
import os
import sys

class xFaceRecognition(object):

    def __init__(self, imageinput="in.jpeg", imageoutput="out.jpeg"):
        self.directorycurrent = os.path.dirname(os.path.realpath(__file__))
        self.directoryoutput = self.directorycurrent
        self.imageinput = imageinput
        self.cascPath = "haarcascade_frontalface_alt.xml"
        self.imageoutput = imageoutput

    def detect(self):
        faceCascade = cv2.CascadeClassifier(self.cascPath)
        image = cv2.imread(self.imageinput)
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        faces = faceCascade.detectMultiScale(
            gray,
            scaleFactor=1.1,
            minNeighbors=5,
            minSize=(30, 30),
            flags = cv2.cv.CV_HAAR_SCALE_IMAGE
        )

        print "Found {0} faces!".format(len(faces))

        for (x, y, w, h) in faces:
            cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
        cv2.imwrite(self.imageoutput, image)
        cv2.waitKey(0)

if __name__ == "__main__":

    idFaceRecognition = xFaceRecognition(imageinput='in.jpeg', imageoutput='out.jpeg')
    idFaceRecognition.detect()

Low Resolution Picture

    root@edison:~/opencv# wget https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2015/09/1442313353nasa-small.jpg
    --2016-03-20 00:49:32--  https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2015/09/1442313353nasa-small.jpg
    Resolving dab1nmslvvntp.cloudfront.net... 23.235.40.133
    Connecting to dab1nmslvvntp.cloudfront.net|23.235.40.133|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 13400 (13K) [image/jpeg]
    Saving to: '1442313353nasa-small.jpg.jpeg'

    100%[======================================>] 13,400      --.-K/s   in 0s      

    2016-03-20 00:49:33 (27.5 MB/s) - '1442313353nasa-small.jpg.jpeg' saved [13400/13400]
    root@edison:~/opencv# mv 1442313353nasa-small.jpg files/photo.jpeg
    root@edison:~/opencv# time python facerecognition.py                       
    Found X faces!

    real    0m2.249s
    user    0m2.010s
    sys     0m0.220s

Look at <>

High Resolution Picture

    root@edison:~/opencv# wget https://upload.wikimedia.org/wikipedia/commons/5/5d/Barack_Obama_family_portrait_2011.jpg
    --2016-03-20 00:24:03--  https://upload.wikimedia.org/wikipedia/commons/5/5d/Barack_Obama_family_portrait_2011.jpg
    Resolving upload.wikimedia.org... 208.80.153.240, 2620:0:860:ed1a::2:b
    Connecting to upload.wikimedia.org|208.80.153.240|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1972894 (1.9M) [image/jpeg]
    Saving to: 'Barack_Obama_family_portrait_2011.jpg'

    100%[======================================>] 1,972,894    264KB/s   in 16s

    2016-03-20 00:24:20 (122 KB/s) - 'Barack_Obama_family_portrait_2011.jpg' saved [1972894/1972894]

    root@edison:~/opencv# mv Barack_Obama_family_portrait_2011.jpg in.jpeg
    root@edison:~/opencv# time python facerecognition.py
    ???

Last updated