return 0; }
效果图:太帅了
图像反转(就是把黑的变白,白的变黑)
黑的变白了,白的变黑了 源码:
#include
#include
int main(int argc,char* argv[]) {
IplImage* img=0;
int height,width,step,channels; UCHAR* data; int i,j,k; if(argc<2) {
printf(\ exit(0); }
img=cvLoadImage(argv[1]); if(!img) {
printf(\ exit(0); }
height=img->height; width=img->width; step=img->widthStep;
channels=img->nChannels;
data=(UCHAR*)img->imageData;
printf(\channels\\n\
cvNamedWindow(\cvMoveWindow(\
for(i=0;i for(k=0;k data[i*step+j*channels+k]=255-data[i*step+j*channels+k]; cvShowImage(\cvWaitKey(0); cvReleaseImage(&img); return 0; } 图像格式的转换 首先要准备一张图片,和几个txt文档,把txt文档的扩展名改成一个你要把图片转换成的格式 我用的原始图片是jpg的,txt改成bmp的 使用时,运行-cmd-cd 转到你的目录- Convert.exe 1.jpg 2.bmp 运行就能把图像1.jpg转换成2.bmp了 源码如下: /* 程序名:convert.c 功能:图像格式的转换 */ #include #include int main( int argc, char** argv ) { IplImage* src; // -1: the loaded image will be loaded as is (with number of channels depends on the file). if(argc != 3) { printf(\JPG,BMP,TIF,PNG,PPM\\n\ printf(\ return 0; } if( ( strstr(argv[1],\&& strstr(argv[1],\ && strstr(argv[1],\&& strstr(argv[1],\&& strstr(argv[1],\ || ( strstr(argv[2],\&& strstr(argv[2],\&& strstr(argv[2],\&& strstr(argv[2],\ && strstr(argv[2],\的用法是不是在a数组内查看是否有b数组。。。没有则输出NULL { printf(\CONV only support JPG,BMP,TIF,PPM,TGA and PPM\\n\ } else { if( (src=cvLoadImage(argv[1], -1))!= 0 ) { cvSaveImage( argv[2], src); cvReleaseImage(&src); printf(\ } else { printf(\ } } return 0; } 发现了个小问题: 原来的jpg图像只有102KB转换成bmp后变成549KB ,在运行程序把这个bmp转成jpg又只有81KB。这真是汗死我了 从摄像头或者AVI文件中得到视频流,对视频流进行边缘检测 /* 程序名称:laplace.c 功能:从摄像头或者AVI文件中得到视频流,对视频流进行边缘检测,并输出结果。 */ #include \ #include \#include int main( int argc, char** argv ) { IplImage* laplace = 0; IplImage* colorlaplace = 0; IplImage* planes[3] = { 0, 0, 0 }; // 多个图像面 CvCapture* capture = 0; // 下面的语句说明在命令行执行程序时,如果指定AVI文件,那么处理从 // AVI文件读取的视频流,如果不指定输入变量,那么处理从摄像头获取 // 的视频流 if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 ); else if( argc == 2 ) capture = cvCaptureFromAVI( argv[1] ); if( !capture ) { fprintf(stderr,\ return -1; } cvNamedWindow( \// 循环捕捉,直到用户按键跳出循环体 for(;;) { IplImage* frame = 0; int i; frame = cvQueryFrame( capture ); if( !frame ) break; if( !laplace ) { for( i = 0; i < 3; i++ ) planes[i] = cvCreateImage( cvSize(frame->width,frame->height), 8, 1 ); laplace = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_16S, 1 ); colorlaplace = cvCreateImage( cvSize(frame->width,frame->height), 8, 3 ); } cvCvtPixToPlane( frame, planes[0], planes[1], planes[2], 0 ); for( i = 0; i < 3; i++ ) { cvLaplace( planes[i], laplace, 3 ); // 3: aperture_size cvConvertScaleAbs( laplace, planes[i], 1, 0 ); // planes[] = ABS(laplace) } cvCvtPlaneToPix( planes[0], planes[1], planes[2], 0, colorlaplace ); colorlaplace->origin = frame->origin; cvShowImage(\ if( cvWaitKey(10) >= 0 ) break; } cvReleaseCapture( &capture ); cvDestroyWindow(\ return 0; } 采用Canny算子进行边缘检测 #include \ #include \ char wndname[] = \ char tbarname[] = \int edge_thresh = 1; IplImage *image = 0, *cedge = 0, *gray = 0, *edge = 0; // 定义跟踪条的 callback 函数 void on_trackbar(int h) { cvSmooth( gray, edge, CV_BLUR, 3, 3, 0 ); cvNot( gray, edge ); // 对灰度图像进行边缘检测 cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 3); cvZero( cedge ); // copy edge points cvCopy( image, cedge, edge ); // 显示图像 cvShowImage(wndname, cedge); } 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库图像处理经典算法及OpenCV程序(3)在线全文阅读。
相关推荐: