Python编程->混合编程(C++,python,opencv)实现
2014-04-15 09:46
477 查看
对于一个程序宅来说,一直有想法把C++,opencv,python结合起来,python的并发性优点,opencv的图像处理算法的优点,C++的灵活,然后就开始了下面的旅程:
配置版本:VS2008+Python2.7+OpenCV2.1.0
源码:
OpenCV2.1.0 sampes里面的Python例程camera.py:
将其放到VS2008的例子python的工程目录下:
然后就开始写代码了:
调用如下:
配置版本:VS2008+Python2.7+OpenCV2.1.0
源码:
OpenCV2.1.0 sampes里面的Python例程camera.py:
将其放到VS2008的例子python的工程目录下:
然后就开始写代码了:
#include "stdafx.h" #include "python.h" #include <tchar.h> #define _AFXDLL #include "stdafx.h" #include <stdio.h> #include <string> #include <iostream> #include <fstream> #include <cstring> #include <afx.h> #include <iostream> using namespace std; #pragma comment (lib,"python27.lib") int test1() { Py_Initialize(); CString strPath; GetCurrentDirectory(MAX_PATH,strPath.GetBuffer(MAX_PATH)); char ch[BUFSIZ]; WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK, (strPath.GetBuffer(strPath.GetLength() + 1)), -1, ch, sizeof(ch), NULL, NULL ); ; strPath.ReleaseBuffer(); string tmpStr; cout << ch << endl; int len = strlen(ch); string fileName = "\\camera.py"; for( int i = 0; i < int(fileName.length()); i++) ch[len++] = fileName[i]; ch[len] = '\0'; cout << ch << endl; PyObject *pyfile = PyFile_FromString(ch,"r"); if(pyfile==NULL) { printf("exit 1"); system("pause"); return 1; } FILE *f = PyFile_AsFile(pyfile); if(f==NULL) { printf("exit 2"); system("pause"); return 1; } PyRun_AnyFileEx(f,"camera.py",0); Py_Finalize(); } int main() { test1(); system("pause"); }点击Run后,打开摄像头如下:
调用如下:
相关文章推荐
- [置顶] Python编程->混合编程(C++,python,opencv)实现
- OpenCV编程->求点集映射关系实现
- OpenCV编程案例:实现一个双目摄像头图像显示的程序
- 编程实现>ASP.NET 3.5开发范例精讲精析>探讨列表控件
- OpenCV编程->OpenMP优化入门
- python实现网络编程 之Twisted框架
- Ubuntu下安装Opencv2.4.9 及实现python接口
- 【python下使用OpenCV实现计算机视觉读书笔记4】保存摄像头视频
- iOS开发之网络编程--4、NSURLSessionDataTask实现文件下载(离线断点续传下载) <进度值显示优化>
- 【python】网络编程-SocketServer 实现客户端与服务器间非阻塞通信
- python扩展实现方法--python与c混和编程
- opencv-python实现垂直投影
- Python GUI编程各种实现的对比
- <基础原理进阶>机器学习算法python实现【3】--文本分析之朴素贝叶斯分类器
- OpenCV编程->Haar训练(1)
- Harris角点检测原理与opencv(python)实现
- python扩展实现方法--python与c混和编程 转自:http://www.cnblogs.com/btchenguang/archive/2012/09/04/2670849.html
- python利用OpenCV2实现人脸检测
- 树莓派驱动步进式电机python编程实现
- Python高级编程-如何实现反向迭代?