图像文件读入和显示
Wikipedia,自由的百科全书
(修订版本间差异)
22:04 2008年6月18日的修订版本 Chai2010 (Talk | 贡献) Python版本 ← Previous diff |
00:30 2008年6月20日的修订版本 Chai2010 (Talk | 贡献) Python版本 Next diff → |
||
第 31行: | 第 31行: | ||
= Python版本 = | = Python版本 = | ||
- | <c> | + | <python> |
# -*- coding:utf-8 -*- | # -*- coding:utf-8 -*- | ||
########################################################### | ########################################################### | ||
第 62行: | 第 62行: | ||
cvShowImage ("mywin", image) | cvShowImage ("mywin", image) | ||
cvWaitKey (0) | cvWaitKey (0) | ||
- | </c> | + | </python> |
注: Python版本由[http://sites.google.com/site/chaishushan/ chai2010]改写. | 注: Python版本由[http://sites.google.com/site/chaishushan/ chai2010]改写. |
00:30 2008年6月20日的修订版本
来自于仕琪的讲稿《使用OpenCV进行图像处理》中的例程 <c>/***********************************************************************
* OpenCV example * By Shiqi Yu 2006 ***********************************************************************/
- include "cv.h"
- include "highgui.h"
int main( int argc, char** argv ) {
IplImage* pImg; //声明IplImage指针
//载入图像 if( argc == 2 && (pImg = cvLoadImage( argv[1], 1)) != 0 ) { cvNamedWindow( "Image", 1 );//创建窗口 cvShowImage( "Image", pImg );//显示图像
cvWaitKey(0); //等待按键
cvDestroyWindow( "Image" );//销毁窗口 cvReleaseImage( &pImg ); //释放图像 return 0; }
return -1;
}</c>
Python版本
<python>
- -*- coding:utf-8 -*-
- OpenCV example
- By ChaiShushan 2008
import sys
- 导入OpenCV模块
from opencv.cv import * from opencv.highgui import *
if __name__ == '__main__':
if len(sys.argv) > 1: # 打开图像
image = cvLoadImage(sys.argv[1]) if not image: sys.exit(-1) # 创建窗口 cvNamedWindow ("mywin") # 显示图像
cvShowImage ("mywin", image) cvWaitKey (0)
</python>
注: Python版本由chai2010改写.