OpenCV 筆記 安裝配置
1. 首先先安裝 OpenCV
安裝路徑:
D:\Work\3_Install\1_Camera_Get\
2. 設定環境變數
在安裝路徑找到 bin的位置 : .\Opencv\build\x64\vc16\bin
D:\Work\3_Install\1_Camera_Get\Opencv\build\x64\vc16\bin
在環境變數 設定 bin 的位置 : .\Opencv\build\x64\vc16\bin
opencv16
D:\Work\3_Install\1_Camera_Get\Opencv\build\x64\vc16\bin
3. 開啟一個 C++ 的專案
4. 環境配置
4.1 其他 include 目錄:
.\Opencv\build\include
.\Opencv\build\include\opencv2
D:\Work\3_Install\1_Camera_Get\Opencv\build\include
D:\Work\3_Install\1_Camera_Get\Opencv\build\include\opencv2
4.2 其他程式庫目錄: .\Opencv\build\x64\vc16\lib
D:\Work\3_Install\1_Camera_Get\Opencv\build\x64\vc16\lib
4.3 其他相依: 在.\Opencv\build\x64\vc16\lib內的 opencv_world4100.lib
opencv_world4100.lib
5. Camera測試
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void Color_Cout(Mat frame,int Select_color1)
{
for (int i = 0; i < frame.rows; i = i + 10)
{
for (int j = 0; j < frame.cols * 3; j = j + 3 * 10)
cout << (int)frame.at<unsigned char>(i, j + Select_color1) << " ";
cout << endl;
}
cout << endl << endl;
}
int main() {
Mat frame0;
VideoCapture cap0(0);
if (!cap0.isOpened()) {
cout << "Cannot open camera 0 \n";
return 1;
}
int Camera_Number = 0;
while (true)
{
bool ret0 = cap0.read(frame0);
if (!ret0)
{
cout << "Can't receive frame 0 (stream end?). Exiting ...\n";
break;
}
imshow("live", frame0);
int WK = waitKey(1);
if (WK == 'q')
{
break;
}
else if (WK == 's')
{
cout << "Camera Size:" << frame0.total() << endl;
}
else if (WK == 'd')
{
int R_color1(2), G_color1(1), B_color1(0);
Color_Cout(frame0, R_color1);
Color_Cout(frame0, G_color1);
Color_Cout(frame0, B_color1);
}
}
return 0;
}
6. DLL的位置
在安裝路徑找到 bin的位置 : .\Opencv\build\x64\vc16\bin
將DLL都丟進去