本站建議搭配 Hover Zoom+ chrome 擴充套件,可自動放大圖片
( 站內文介紹: https://goo.gl/BnBSGa )
網站搜索不是很好用建議使用google底下括號內是範例,整串打進google搜索內;
[ site:https://charlottehong.blogspot.tw/ 你要搜索的內容 ]
2017年1月12日 星期四
2016年5月29日 星期日
C++ OpeCV 2.4.13 for Windows MinGW g++ [在 window上使用 MinGW g++ 編譯 opencv]
C++ OpenCV 2.4.13 for Windows MinGW g++
在 window上使用 MinGW g++ 編譯 opencv
前言
這幾天想用 MinGw 編譯 OpenCV,資料有些零散中文也不多
花了不少時間把搜尋資料,做好之後有順便做了一個懶人包
如果新手剛學,建議可以直接用懶人包就好了
花了不少時間把搜尋資料,做好之後有順便做了一個懶人包
如果新手剛學,建議可以直接用懶人包就好了
懶人包已經簡化到只需按兩個安裝按鈕,就這樣而已
還有編譯時只要把g++替換成cv2就好了
cv2 file.cpp -o file 就這樣,幫你處理掉重複又很長的代碼了
還有編譯時只要把g++替換成cv2就好了
cv2 file.cpp -o file 就這樣,幫你處理掉重複又很長的代碼了
安裝
以下是安裝步驟:(建議使用預設位置)
1.開啟 MingGW AutoInstall
2.開啟 OpenCV2413 AutoInstall
3.開啟 OpenCV_Tester
1.開啟 MingGW AutoInstall
2.開啟 OpenCV2413 AutoInstall
3.開啟 OpenCV_Tester
很神奇的就安裝完畢瞜~
注意:如果已經安裝過MingGW,請移除在安裝(環境變數也要移除)
程序並沒有防呆會處理這個狀況,會出問題的。
注意:如果已經安裝過MingGW,請移除在安裝(環境變數也要移除)
程序並沒有防呆會處理這個狀況,會出問題的。
看看有沒有跳出測試通過,有的話就可以開始使用了
如何以命令編譯C++檔案
懶人包
如何編譯指令在 OpenCV_Tester 內有說明
終端機輸入 cv2 souce.cpp -o souce 這樣即可
終端機輸入 cv2 souce.cpp -o souce 這樣即可
命令
原本的代碼則是:(這裡是依照我的檔案路徑)
g++ -Wall -std=c++14 -IC:\OpenCV\include\ -LC:\OpenCV\MinGw_64\lib\ -lopencv_core2413 -llibopencv_calib3d2413 -llibopencv_core2413 -llibopencv_features2d2413 -llibopencv_flann2413 -llibopencv_highgui2413 -llibopencv_imgproc2413 -llibopencv_video2413 main.cpp -o opencv.exe
如果是安裝我的懶人包,可以使用
cv2
來替換cv2 souce.cpp -o souce
- 20170721更新命令先前有缺失,某些庫不能編,懶人包與sublime配置檔我還沒更新
重新編譯OpenCV檔案
如果你要自己編譯其實也沒到多複雜只是很多設定要自己來別漏掉就好了
跟linux一樣,cmake編譯,然後產出的文件在依照規定對應就完成瞜
跟linux一樣,cmake編譯,然後產出的文件在依照規定對應就完成瞜
標籤:
OpenCV
2015年11月12日 星期四
How to Install OpenCV3.0 for Mint17 or Ubuntu15.10
如何在 Mint17 或 ubuntu15安裝 OpenCV3.0
Mint17:
1.install files
3.make
4.patch
open this file
open this file
Finish
=====================================================================
unubtu15.10
=====================================================================
TestFile
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.confadd
"/usr/local/lib"and run "sudo ldconfig "
open this file
sudo gedit /etc/bash.bashrcadd
"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
標籤:
OpenCV
2015年8月17日 星期一
Python2.7 如何在 Win10 上安裝 OpenCV 函式庫
Python2.7 如何在 Win10 上安裝 OpenCV 函式庫
安裝
再來安裝Numpy,這個其實不是OpenCV必備的,沒有也可以執行,只是這個太常用了,幾乎可以是說是python必裝的,很容易在OpenCV教學的範例代碼上見到。就直接安裝省事吧~~
按下 Win+X 在按 A 打開終端機,然後輸入
python -m pip install numpy
安裝 OpenCV
先說最簡單的方式,跟上面一樣直接執行 pip 安裝。
這個方式會直接安裝pip裡面的opencv,缺點是不能選版本。我這邊測試目前是直接幫我安裝最新版本 OpenCV4.1.0 了,如果OpenCV剛出新版本可能需要等一下。
這個方式會直接安裝pip裡面的opencv,缺點是不能選版本。我這邊測試目前是直接幫我安裝最新版本 OpenCV4.1.0 了,如果OpenCV剛出新版本可能需要等一下。
如果你只是要可以執行opencv並不挑版本的初學者,可以直接執行就好。
python -m pip install OpenCV-Python
測試執行範例
測試用的程式 Drawing.py
https://gist.github.com/hunandy14/c67ee781b99322a2d1cf
https://gist.github.com/hunandy14/c67ee781b99322a2d1cf
載下來之後,預設狀態直接用點兩下執行就好了,如果你把它修改成用編譯器打開這邊你在用自己的方式執行程式即可。
手動安裝 OpenCV
上面執行沒問題這邊就不用做了噢~給需要換版本的人看的。
OpenCV:https://opencv.org/releases/
載下來的 OpenCV 可以直接右鍵使用 rar 打開或是點兩下直接安裝到桌面即可。
載下來的 OpenCV 可以直接右鍵使用 rar 打開或是點兩下直接安裝到桌面即可。
然後找到這個位置
opencv-4.1.0-vc14_vc15.exe\opencv\build\python\cv2\python-2.7
裡面有一個檔案
把這個檔案複製到下面這個位置,如果你有改python安裝位置這邊要自己找到。
cv2.pyd
這個是官方已經預先編譯好的檔案,直接拿過來就可以了。把這個檔案複製到下面這個位置,如果你有改python安裝位置這邊要自己找到。
C:\Python27\Lib\site-packages
至此就完成安裝了,其實也沒多複雜拉XDD
標籤:
OpenCV
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()
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()
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()
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()
# -*- 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()
訂閱:
文章 (Atom)