OpenCV Configuration, Python & C++
1 Linux + Python
# 1 not using cv.imshow()
pip install opencv-python
# 2 using cv.imshow(), but can't read video files
conda remove opencv
conda install -c menpo opencv
2 Win 10 + Python
2.1 安装
版本:Win 10 + Python 3.7 + OpenCV 3.4.3
时间:2018.11.17
2.2 Canny边缘检测demo
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('tower.jpg')
edge = cv2.Canny(img,100,200)
plt.subplot(121)
plt.imshow(img)
plt.title('Original Image')
plt.xticks([]), plt.yticks([])
plt.subplot(122)
plt.imshow(edge)
plt.title('Edge Image')
plt.xticks([]), plt.yticks([])
plt.show()
3 Win 10 + C++
3.1 安装
版本:Win 10 + VS 2013 + OpenCV 2.4.13
时间:2018.11.17
OpenCV 发布页面,OpenCV releases,选择2.4.13- winpack下载,双击解压即可。
3.2 配置项目
注意,我的 opencv-2.4.13.exe 解压目录为 D:\opencv
,请根据你的目录修改路径。
-
添加环境变量
path中添加
D:\opencv\build\x86\vc12\bin;
-
配置项目目录
选择 Project - Properties - VC++ Directories
Include Directories 中添加
D:\opencv\build\include;
Library Directories 中添加
D:\opencv\build\x86\vc12\lib;
-
配置链接
选择 Project - Properties - Linker - Input
Additional Dependencies 中添加下列内容。(默认是debug模式,)
opencv_ml2413d.lib opencv_calib3d2413d.lib opencv_contrib2413d.lib opencv_core2413d.lib opencv_features2d2413d.lib opencv_flann2413d.lib opencv_gpu2413d.lib opencv_highgui2413d.lib opencv_imgproc2413d.lib opencv_legacy2413d.lib opencv_objdetect2413d.lib opencv_ts2413d.lib opencv_video2413d.lib opencv_nonfree2413d.lib opencv_ocl2413d.lib opencv_photo2413d.lib opencv_stitching2413d.lib opencv_superres2413d.lib opencv_videostab2413d.lib
tips
-
项目编译通过,Debug阶段报错,“应用程序无法正常启动(0xc000007b)”。
x86/x64平台问题,检查环境变量与项目配置中,所使用的是哪一个版本。
3.3 Canny边缘检测demo
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
int main()
{
Mat src, edge;
src = imread("1.jpg");
// Canny edge
Canny(src, edge, 100, 200);
imshow("Canny edge", edge);
waitKey(0);
return 0;
}