2015年11月12日 星期四

How to Install OpenCV3.0 for Mint17 or Ubuntu15.10

如何在 Mint17 或 ubuntu15安裝 OpenCV3.0

Mint17:

1.install files
sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
sudo apt-get update
sudo apt-get install libopencv-dev build-essential checkinstall cmake pkg-config yasm libtiff4-dev libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg 


2.downlods
cd ~/
mkdir OpenCV3_Install
cd OpenCV3_Install
sudo apt-get install git
git clone https://github.com/Itseez/opencv.git

3.make
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
make -j4
sudo make install

4.patch

open this file
sudo gedit /etc/ld.so.conf.d/opencv.conf
add
"/usr/local/lib"
and run "sudo ldconfig "

open this file
sudo gedit /etc/bash.bashrc
add
"PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig"
"export PKG_CONFIG_PA"

Finish


=====================================================================
unubtu15.10

# 安裝需要的套件
sudo apt-get install libopencv-dev build-essential checkinstall cmake pkg-config yasm libtiff5-dev libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg

# 下載/OpenCV
cd ~/
mkdir OpenCV3_Install
cd OpenCV3_Install
sudo apt-get install git
git clone https://github.com/Itseez/opencv.git

# 準備編譯
cd opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

# 開始編譯
make -j4
sudo make install




sudo apt-get install gedit
clear
echo "================================="
echo "Now Add to file"
echo "================================="
echo "/usr/local/lib"
echo "================================="
sudo gedit /etc/ld.so.conf.d/opencv.conf
sudo ldconfig
clear
echo "================================="
echo "Now Add to file"
echo "================================="
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig"
echo "export PKG_CONFIG_PATH"
echo "================================="
sudo gedit /etc/bash.bashrc
echo "OpenCV version is"
pkg-config --modversion opencv

=====================================================================
TestFile
# -*- coding: utf-8 -*-
import cv2
import numpy as np
#  畫布大小
img = np.zeros((720,1280,3), np.uint8)
# (位置),大小,(顏色)粗度
cv2.circle(img,(200,200), 100, (0,0,255), 2)
# (第一個座標)(第二個座標)(顏色),粗度
cv2.rectangle(img,(350,100),(550,300),(0,255,0),3)
# (第一個座標)(第二個座標)(顏色),粗度
cv2.line(img,(600,100),(800,300),(255,0,0),10)
pts = np.array([[10,5],[20,30],[70,20],[50,10]], np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img,[pts],True,(0,255,255))
font = cv2.FONT_HERSHEY_SIMPLEX
# (座標),大小,(顏色),粗度
cv2.putText(img,'Charlotte.HonG',(0,500), font, 5,(255,255,255),10,cv2.LINE_AA)
while(1):
    cv2.imshow('Dring',img)
    if cv2.waitKey(20) & 0xFF == 27:
        break
cv2.destroyAllWindows()

Press "Esc" Exit

2015年8月18日 星期二

WebCamera_Show

import numpy as np
import cv2

cap = cv2.VideoCapture(0)
# Define the codec and create VideoWriter object
fourcc = cv2.cv.CV_FOURCC('m', 'p', '4', 'v')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        # Video reverse =0
        # frame = cv2.flip(frame,0)
        frame = cv2.flip(frame,1)
        # write the flipped frame
        out.write(frame)
        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()

2015年8月17日 星期一

Windows Install OpenCV for Python

  1.  Install : Python-2.7.10.msi
  2. Add System Pach 【;C:\Python27;C:\Python27\Scripts】
  3. Install : Numpy-1.9.2-win32-Superpack-python2.7.exe
  4. Copy “cv2.pyd” to “Python27\Lib\site-packages\”
  5. Open Drawing.py
cv2.pyd in the OpenCV
【2.4.11.exe\opencv\build\python\2.7\x86】


測試用的程式
Drawing.py
https://gist.github.com/hunandy14/c67ee781b99322a2d1cf



如果你要安裝新版的numpy可以直接下載最新版的


把它解壓縮放到桌面,開啟CMD
這裡已numpy-1.11.0示範
輸入 cd %USERPROFILE%/Desktop/numpy-1.11.0
接下來輸入 setup.py build
沒意外會失敗,注意看訊息的最後一行,有給網址

http://aka.ms/vcpython27


進去之後連結到微軟的官方,下載並安裝
然後再次執行 setup.py build
執行完畢安裝 setup.py install
然後就完成了




2015年8月11日 星期二

opencv 檢視灰階影像

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

opencv 滑鼠點擊繪圖

import cv2
import numpy as np

drawing = False # true if mouse is pressed
mode = True # if True, draw rectangle. Press 'm' to toggle to curve
ix,iy = -1,-1

# mouse callback function
def draw_circle(event,x,y,flags,param):
    global ix,iy,drawing,mode

   
    if event == cv2.EVENT_LBUTTONDBLCLK:
        cv2.circle(img,(x,y),100,(255,0,0),-1)

    elif event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        ix,iy = x,y

    elif event == cv2.EVENT_MOUSEMOVE:
        if drawing == True:
            if mode == True:
                cv2.rectangle(img,(ix,iy),(x,y),(0,255,0),-1)
            else:
                cv2.circle(img,(x,y),5,(0,0,255),-1)

    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False
        if mode == True:
            cv2.rectangle(img,(ix,iy),(x,y),(0,255,0),-1)
        else:
            cv2.circle(img,(x,y),5,(0,0,255),-1)

img = np.zeros((512,512,3), np.uint8)
cv2.namedWindow('image')
cv2.setMouseCallback('image',draw_circle)

while(1):
    cv2.imshow('image',img)
    k = cv2.waitKey(1) & 0xFF
    if k == ord('m'):
        mode = not mode
    elif k == 27:
        break

cv2.destroyAllWindows()

opencv 錄影

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

# Define the codec and create VideoWriter object
fourcc = cv2.cv.CV_FOURCC('m', 'p', '4', 'v')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)

        # write the flipped frame
        out.write(frame)
       
        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()

Opencv 繪圖

繪製各種形狀的圖形



# -*- coding: utf-8 -*-
import cv2
import numpy as np

#  畫布大小
img = np.zeros((720,1280,3), np.uint8)
# (位置),大小,(顏色)粗度
cv2.circle(img,(200,200), 100, (0,0,255), 2)
# (第一個座標)(第二個座標)(顏色),粗度
cv2.rectangle(img,(350,100),(550,300),(0,255,0),3)
# (第一個座標)(第二個座標)(顏色),粗度
cv2.line(img,(600,100),(800,300),(255,0,0),10)

pts = np.array([[10,5],[20,30],[70,20],[50,10]], np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img,[pts],True,(0,255,255))

font = cv2.FONT_HERSHEY_SIMPLEX
# (座標),大小,(顏色),粗度
cv2.putText(img,'Charlotte.HonG',(0,500), font, 5,(255,255,255),10,cv2.CV_AA)

while(1):
    cv2.imshow('Dring',img)
    if cv2.waitKey(20) & 0xFF == 27:
        break
cv2.destroyAllWindows()

2015年6月3日 星期三

UART(RX TX) RaspberryPI 與 Arduino 互傳字串

將Arduino與RasveryPi版上的RX與TX互接(PiRX=ArduiTX)
Pi版上請參考該技術手冊,Arduino則由程式碼內可得知



執行:ps ax | fgrep AMA

你會看到
2039 ? Ss+ 0:00 /sbin/getty -L ttyAMA0 115200 vt100
2055 pts/0 S+ 0:00 fgrep --color=auto AMA
確認無誤之後,繼續輸入以下指令:
sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt
將cmdline.txt備份
sudo vim /boot/cmdline.txt

cmdline.txt如下:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
將它改為:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

2015年5月29日 星期五

Raspberry Pi B+ 使用網頁控制LED

編譯python檔在Pi上使用指令控制LED【w=亮;s=滅】

vim led_str_ctrl.py

按i並貼上底下程式碼:
====================================================================
#!/usr/bin/python
import RPi.GPIO as G # reference the GPIO library
G.setmode(G.BCM) # use the 'BCM' numbering scheme for the pins
G.setup(18, G.OUT) # Set pin 18 as an Output
while (True): # keep going around this loop until we're told to quit
key = raw_input("Enter 'w' for On, 's' for Off and any other key to quit. You'll need to press enter after each character: ")
if key == "w":
G.output(18, True) # Turn it on
elif key == "s":
G.output(18, False) # Turn it off
else:
break # leave our loop
G.cleanup() # Tidy up after ourselves so we don't generate warnings next time we run this

2015年5月24日 星期日

ASUS_AR-Z97_ACPI在裝置管理員出現驚嘆號_ACPI\PNP0A0A

ASUS ACPI在裝置管理員出現驚嘆號_ACPI\PNP0A0A

驅動少裝

爬文有發現,AMD00要先安裝否則系統會有驚嘆號

補裝還是有問題

將他右鍵解除裝置,隨後重新開機仍會有驚嘆號
此時滑鼠靈敏度出現一點異常(我的會這樣其他電腦可能不會)
重新安裝AMD00驅動一次
Win7資料夾內與外都用右鍵管理安裝,再重新開機一次就好了。
-
2015/05/24 紀錄本次處理流程,仍未知關鍵性操作。
就這樣做就好了,確定是少裝AMD00,不過有時候裝了還會出現
建議優先安裝AMD00,後來嘗試這樣做好像一次解決了