樹莓派相機︰ RaspiCAM 之軟件《三》

講到 RaspiCAM 之應用軟件程式庫,焉能不提及大名鼎鼎的

 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.

ABOUT

OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products. Being a BSD-licensed product, OpenCV makes it easy for businesses to utilize and modify the code.

The library has more than 2500 optimized algorithms, which includes a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms. These algorithms can be used to detect and recognize faces, identify objects, classify human actions in videos, track camera movements, track moving objects, extract 3D models of objects, produce 3D point clouds from stereo cameras, stitch images together to produce a high resolution image of an entire scene, find similar images from an image database, remove red eyes from images taken using flash, follow eye movements, recognize scenery and establish markers to overlay it with augmented reality, etc. OpenCV has more than 47 thousand people of user community and estimated number of downloads exceeding 7 million. The library is used extensively in companies, research groups and by governmental bodies.

Along with well-established companies like Google, Yahoo, Microsoft, Intel, IBM, Sony, Honda, Toyota that employ the library, there are many startups such as Applied Minds, VideoSurf, and Zeitera, that make extensive use of OpenCV. OpenCV’s deployed uses span the range from stitching streetview images together, detecting intrusions in surveillance video in Israel, monitoring mine equipment in China, helping robots navigate and pick up objects at Willow Garage, detection of swimming pool drowning accidents in Europe, running interactive art in Spain and New York, checking runways for debris in Turkey, inspecting labels on products in factories around the world on to rapid face detection in Japan.

It has C++, C, Python, Java and MATLAB interfaces and supports Windows, Linux, Android and Mac OS. OpenCV leans mostly towards real-time vision applications and takes advantage of MMX and SSE instructions when available. A full-featured CUDA and OpenCL interfaces are being actively developed right now. There are over 500 algorithms and about 10 times as many functions that compose or support those algorithms. OpenCV is written natively in C++ and has a templated interface that works seamlessly with STL containers.

OpenCV Developers Team:

 

之前 o4l 【only for linux】老友寫過 Python 2.7 的

opencv 3 安裝

,據聞當時 Python 3.x 還有些編譯問題。由於作者偏好派生三支援萬國碼,能寫中文化程式。因此嘗試安裝最新 github 原始碼,終究皇天不負苦心人乎!

sudo apt-get install build-essential git cmake pkg-config
sudo apt-get install libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python3-dev
sudo pip-3.2 install numpy
git clone https://github.com/Itseez/opencv.git
git clone https://github.com/Itseez/opencv_contrib.git
cd opencv
mkdir build
build/
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D BUILD_EXAMPLES=ON ..
make -j4
sudo make install
sudo ldconfig
cd
ln -s /usr/local/lib/python3.4/dist-packages/cv2.cpython-34m.so cv2.so

 

將要如何驗證安裝的呢?一時想起了曾經讀過之癹文 POST︰

Install OpenCV 3.1 Python/C++ on Raspbian Jessie

。於是依樣畫葫蘆一番耶!

pi@raspberrypi:~ python3 Python 3.4.2 (default, Oct 19 2014, 13:31:11)  [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 >>> print (cv2.__version__) 3.1.0-dev >>>  </pre>   <pre class="lang:python decode:true ">mkdir test cd test nano 樹莓派相機測試.py  pi@raspberrypi:~/test more 樹莓派相機測試.py 
import numpy as np
import cv2
擷取 = cv2.VideoCapture(0)
if 擷取.isOpened() == False:
    print('錯誤: 不能打開相機')
else:
    print('開始擷取,按任意鍵結束')
    cv2.namedWindow('擷取視窗');
    while( 擷取.isOpened() ):
        傳回值,畫面 = 擷取.read()
        if 傳回值==False:
            print('錯誤: 不能擷取畫面')
            break;
 
        cv2.imshow('擷取視窗',畫面)
        if cv2.waitKey(1) >= 0:
           break
    print('關閉相機')
 
擷取.release()
cv2.destroyAllWindows()
print('再見')
pi@raspberrypi:~/test python3 樹莓派相機測試.py  開始擷取,按任意鍵結束 關閉相機 再見 pi@raspberrypi:~/test

 

%e6%93%b7%e5%8f%96%e8%a6%96%e7%aa%97