【OpenCV】OpenCV2.4.6 与Visiual Studio 2008,Python2.7.5配置和图像载入显示
自从OpenCV2.2开始,OpenCV 库便分成几个模块并位于lib文件中,本节介绍从OpenCV2.4.6与VS2008 、Python2.7.5如何配置环境,如何外部文件载 入图像、在窗口中显示图像。
配置环境
Installing OpenCV2.4.6 for Visual Studio 2008
Step 1: Download OpenCV2.4.6.exe from http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.6/. Run OpenCV-2.4.6-win-superpack.exe and copy the generated folder OpenCV2.4.6 to D drive
Step 2: Open Microsoft Visual Studio 2008 and click Tools->Options
Select Projects and Solutions and then VC++ Directories. Select Include files in Show directories for: drop down menu. Add the following paths.
D:\Program Files\OpenCV2.4.6\VS2008\include
Select Library files in Show directories for: drop down menu. Add the following path.
D:\Program Files\OpenCV2.4.6\VS2008\lib\Debug
D:\Program Files\OpenCV2.4.6\VS2008\lib\Release
Now we have added include and library file paths and this need to be done only for the first time.
Step 3: Create an new project in Visual Studio 2008
Click Project->Properties. Select Configuration Properties -> Linker -> Input. Make sure you select Debug in 'Configuration:' drop down menu and then add the following to the Additional Dependencies.
opencv_features2d246d.lib opencv_highgui246d.lib opencv_core246d.lib opencv_imgproc246d.lib opencv_ml246d.lib opencv_objdetect246d.lib opencv_video246d.lib opencv_contrib246d.lib opencv_calib3d246d.lib
Now select Release in 'Configuration:' drop down menu and then add the following to the Additional Dependencies and click OK
opencv_features2d246.lib opencv_highgui246.lib opencv_core246.lib opencv_imgproc246.lib opencv_ml246.lib opencv_objdetect246.lib opencv_video246.lib opencv_contrib246.lib opencv_calib3d246.lib
Step 4:
Add D:\Program Files\OpenCV2.4.6\bin to the environment path as shown in screenshot below. You may need to restart the system after setting this.
Installing OpenCV2.4.6 for Python 2.7.5
i have always struggled when trying to set up OpenCV for Python before. So I decide to write this post to help myself in the future and share with you =). My setup is for OpenCV 2.2 but I think you can apply for any version of OpenCV.
Step 1: Download and install Python 2.7.5 from http://www.python.org/getit/releases/2.7.5/. You need to install the 32bit version of Python.
Step 2: Download and install OpenCV 2.4.6 from http://sourceforge.net/projects/opencvlibrary/files/. Note that this version only supports Python 2.7.5 (not 3.x).
Step 3: Download and install NumPy 1.6.1 and SciPy 0.9.0 from: (you need to choose the files which support Python 2.7)
- http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/
- http://sourceforge.net/projects/scipy/files/scipy/0.9.0/
Step 4:Setup Windows Path in Environment Variables
- Add “D:/Python2.7.5;D:/OpenCV2.4.6/bin” to PATH variable (You need to change the directory to where you install Python and OpenCV).
- Create PYTHONPATH variable and put “D:/OpenCV2.4.6/Python2.7.5/Lib/site-packages” as value.
图像载入和显示
我们第一件事是就是如何声明一个表示图像的变量,在OpenCV 2.XX中,这个变量将是cv:Mat类型.
cv:Mat img;
接着是,一个简单的读取函数将进行寻文件读取,解码以及内存的分配。
img = cv:imread("../../../waves.jpg");
首先在显示图像之前时,需定义一个图像显示的窗口,接着指定需要显示的图像。
cv::namedWindow("Original Window"); // define the window
cv::imshow("Original Window",img); //show img in the window
现在如果我们需要对图像进行一些处理,如flip函数,然而,我们也可以创建另外一个矩阵来保存输出结果:
cv::Mat result;
cv::flip(img,result,1); // positive for horizontal;
// 0 for vertical;
// negative for both
结果显示在另一个窗口中:
cv::namedWindow("Output Window");
cv::imshow("Output Window",result);
由于这个管制台窗口。它会在main函数的结尾处终结,因此我们添加额外highgui 函数使得程序退出胶不停等待用户的按键入:
cv::waitKey(0);
现在,给相关完整C++版代码和Python版代码.
完整代码
C++版
//
// display_image.cpp : Defines the entry point for the console application.
// #include "stdafx.h"
#include "opencv2/opencv.hpp" int _tmain(int argc, _TCHAR* argv[])
{
cv::Mat img = cv::imread("../../../waves.jpg"); cv::Mat result;
cv::flip(img,result,1); // positive for horizontal;
// 0 for vertical;
// negative for both cv::namedWindow("Original Window"); // define the window
cv::namedWindow("Output Window"); cv::imshow("Original Window",img); //show img in the window
cv::imshow("Output Window",result); cv::waitKey(0);
cv::destroyAllWindows(); return 0;
}
Python版
''' filename : display_image.py
Benefits : Learn to load image and display it in window''' import cv2 img = cv2.imread("../waves.jpg")
Result =cv2.flip(img,1) cv2.namedWindow('Original Window')
cv2.imshow('Original Window',img) #Show Original image in the window
cv2.namedWindow('Output Window')
cv2.imshow('Output Window',Result) cv2.waitKey(0)
cv2.destroyAllWindows() #Destroy all windows
本人测试C++版和Python版 图像输出结果一样,并未什么细微显示差别。
图像输出结果
未完,待续........
====================================================== 转载请注明出处:http://blog.csdn.net/utimes/article/details/9388541======================================================
【OpenCV】OpenCV2.4.6 与Visiual Studio 2008,Python2.7.5配置和图像载入显示的更多相关文章
- 关于在Visual Studio 2008/2010 和Opencv平台下出现LINK : fatal error
http://blog.sina.com.cn/s/blog_9015f3230101bbef.html 关于在Visual Studio 2008/2010 和Opencv平台下出现LINK : f ...
- [vs2008]Visual Studio 2008 SP1添加或删除功能提示查找SQLSysClrTypes.msi文件
前言 今天接到领导布置的一个任务,是之前同事负责的项目.离职了,现在客户有些地方需要修改,由于我之前参与过,就落在我的头上了. 然后我就把代码弄了过来,打开发现其中需要用到水晶报表.(我觉得不好用,不 ...
- Microsoft Visual Studio 2008 未能正确加载包“Visual Web Developer HTML Source Editor Package” | “Visual Studio HTM Editor Package”
在安装Microsoft Visual Studio 2008 后,如果Visual Studio 2008的语言版本与系统不一致时,比如:在Windows 7 English System 安装Vi ...
- Visual Studio 2008 Package Load Failure:未能正确加载包“Microsoft.VisualStudio.Xaml”
在安装好Visual Studio 2008后,启动Visual Studio 2008 发现如下提示: 包加载失败 未能正确加载包“Microsoft.VisualStudio.Xaml”( GUI ...
- 打开office word excel弹出visual studio 2008
打开office word 或者excel或者ppt等文档就会弹出visual studio 2008正在配置对话框. 按照我下面的步骤,解决方法非常简单. 如果你的电脑是win7操作系统,从第一步开 ...
- 安装了SQL2005再安装SQL 2008R2,提示此计算机上安装了 Microsoft Visual Studio 2008 的早期版本和检查是否安装了 SQL Server 2005 Express 工具的解决方案
工作电脑上安装了SQL 2005, 但是客户电脑上安装的是SQL 2008R2,有时候连接他们的库调试没法连接,很不方便.然后又安装了个SQL2008 R2,期间遇到这两个问题,网上搜索了一下收到了解 ...
- Visual Studio 2008打开vs2010解决方案的方法
一个朋友遇到了个问题:用visual studio 2008软件,无法打开一个asp.net网站的sln解决方案.如下图,原因是此解决方案由vs2010生成的,必须由vs2010运行程序打开. 这样一 ...
- Visual Studio 2008 使用 WinCE 5.0 Emulator
1. 簡介 由於 Visua Studio 2008 與 WinCE 5.0 Emulator 並沒有完全整合,因此想要測試我們所開發的 Windows CE 程式,需透過設定,將我們所開發的程式丟到 ...
- Visual Studio 2008破解激活升级方法
声明:本文中涉及到的序列号及更新方法均来自互联网,请支持正版. 微软为业余爱好者.热衷者和学生提供了免费版——Express Edition (轻型.易学.易用的开发工具). 如不想支付任何费用,建议 ...
随机推荐
- iOS合并静态库文件
具体命令如下(在控制台输入如下命令): lipo -create 其中一个要合并的静态库 另一个要合并的静态库 -output 合并后的静态库
- 【转载】VC++中的图像类型转换--使用开源CxImage类库
一.CxImage类库简介 这只是翻译了CxImage开源项目主页上的部分简介及简单使用. CxImage类库是一个优秀的图像操作类库.它可以快捷地存取.显示.转换各种图像.有的读者可能说,有那么多优 ...
- mysql 创建表字段类型笔记
1.字段联合唯一,unique(ServerVersion , MobileVersion, MobileType) .并且mysql设置多个字段为主键是起不到约束唯一的作用. 2.二进制用 BLOB ...
- python安装集成包
anaconda, 包含各种科学运算包以及astropy.装完它一劳永逸. https://www.continuum.io/downloads
- [LeetCode]题解(python):130-Surrounded Regions
题目来源: https://leetcode.com/problems/surrounded-regions/ 题意分析: 给定给一个二维的板,这个板只包括‘X’和‘O’.将被‘X’包围的‘O’变成‘ ...
- Google日历添加农历、节日和天气插件(步骤)
Google日历添加农历.节日和天气插件(步骤) Google功能非常多,Google日历只是其中一个,而且支持Exchange账户(iPhone,WP7,诺基亚等)和Google账户登录(andro ...
- Protel 99SE PCB 打印技巧
1. 打开 Protel99SE PCB 设计文档.从菜单File 下单击Print/Preview 打印预览菜单.出现PCB 打印预览介面. 2.从File 下单击 Setup Printer 设置 ...
- 基于Visual C++2013拆解世界五百强面试题--题7-链表的各种操作
请用C实现一个链表,实现链表的查找,逆置,替换,删除,添加,清空,创建. 查找.替换和删除.添加里面都会用到遍历链表的操作,所以重点在于遍历, 链表的逆置和清空考虑到效率,我们可以用递归实现, 至于创 ...
- Objective-c @property和@Synthesize
在Objective-c中,使用@property来标识属性(一般是实例变量).在实现文件中使用@synthesize标识所声明的变量,让系统自动生成设置方法和获取方法. 也就是说@property和 ...
- Android开发中内置apk程序
首先申明,这里的方法介绍是针对我司自己项目中的具体开发板而做的. Mg701内置APK有三种方式 一. 这种方法必须要自己编写Android.mk文件(关于Android.mk可以参考 ...