77范文网 - 专业文章范例文档资料分享平台

图像处理经典算法及OpenCV程序(2)

来源:网络收集 时间:2018-12-04 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

static int num=0;

if(Event==CV_EVENT_LBUTTONDOWN) {

if(num==4)num=0;//只是固定定义了保存4张图片,为了不让程序非法而设置的复原

cvcamPause(); //图像保存

// cvSaveImage(strleft[num],image1); cvSaveImage(strright[num],image2); // cvSaveImage(\ // cvSaveImage(\ }

if(Event==CV_EVENT_RBUTTONDOWN) {

cvcamResume(); num++; } }

能激发你用代码做视频的冲动程序

这个程序是基于opencv的,连接库就不说了,直接建立一个基于win32的控制台程序,写代码就OK了。

/* 程序名:drawing..c

功能:展示OpenCV的图像绘制功能 */

#include \

#include \#include #include #define NUMBER 100 #define DELAY 5

char wndname[] = \

CvScalar random_color(CvRNG* rng) //函数 cvRNG 初始化随机数生成器并返回其状态,RNG 随机数生成器 {

int icolor = cvRandInt(rng); //函数 cvRandInt 返回均匀分布的随机 32-bit 无符号整型值并更新 RNG 状态

return CV_RGB(icolor&255, (icolor>>8)&255, (icolor>>16)&255); //

创建 一个色彩值 }

int main( int argc, char** argv ) {

int line_type = CV_AA; // change it to 8 to see non-antialiased graphics int i;

CvPoint pt1,pt2; //基于二维整形坐标轴的点 double angle;

CvSize sz; //矩形框大小,以像素为精度 CvPoint ptt[6]; CvPoint* pt[2]; int arr[2]; CvFont font; CvRNG rng;

int width = 1000, height = 700;

int width3 = width*3, height3 = height*3; CvSize text_size; int ymin = 0;

// Load the source image

IplImage* image = cvCreateImage( cvSize(width,height), 8, 3 ); IplImage* image2;

// Create a window

cvNamedWindow(wndname, 1 );

cvZero( image ); //#define cvZero cvSetZero void cvSetZero( CvArr* arr ); arr 要被清空数组

cvShowImage(wndname,image); rng = cvRNG((unsigned)-1); pt[0] = &(ptt[0]); pt[1] = &(ptt[3]); arr[0] = 3; arr[1] = 3;

for (i = 0; i< NUMBER; i++) {

pt1.x=cvRandInt(&rng) % width3 - width; pt1.y=cvRandInt(&rng) % height3 - height; pt2.x=cvRandInt(&rng) % width3 - width; pt2.y=cvRandInt(&rng) % height3 - height;

cvLine( image, pt1, pt2, random_color(&rng), cvRandInt(&rng), line_type, 0 );//绘制连接两个点的线段 cvShowImage(wndname,image); cvWaitKey(DELAY); }

for (i = 0; i< NUMBER; i++) {

pt1.x=cvRandInt(&rng) % width3 - width; pt1.y=cvRandInt(&rng) % height3 - height; pt2.x=cvRandInt(&rng) % width3 - width; pt2.y=cvRandInt(&rng) % height3 - height;

cvRectangle( image,pt1, pt2, random_color(&rng),

cvRandInt(&rng)-1, line_type, 0 );//绘制简单、指定粗细或者带填充的 矩形

cvShowImage(wndname,image); cvWaitKey(DELAY); }

for (i = 0; i< NUMBER; i++) {

pt1.x=cvRandInt(&rng) % width3 - width; pt1.y=cvRandInt(&rng) % height3 - height; sz.width =cvRandInt(&rng) 0; sz.height=cvRandInt(&rng) 0;

angle = (cvRandInt(&rng)00)*0.180;

cvEllipse( image, pt1, sz, angle, angle - 100, angle + 200, random_color(&rng), cvRandInt(&rng)-1, line_type, 0 );//函数cvEllipse用来绘制或者填充一个简单的椭圆弧或椭圆扇形 cvShowImage(wndname,image); cvWaitKey(DELAY); }

for (i = 0; i< NUMBER; i++) {

pt[0][0].x=cvRandInt(&rng) % width3 - width; pt[0][0].y=cvRandInt(&rng) % height3 - height; pt[0][1].x=cvRandInt(&rng) % width3 - width; pt[0][1].y=cvRandInt(&rng) % height3 - height; pt[0][2].x=cvRandInt(&rng) % width3 - width; pt[0][2].y=cvRandInt(&rng) % height3 - height; pt[1][0].x=cvRandInt(&rng) % width3 - width; pt[1][0].y=cvRandInt(&rng) % height3 - height;

pt[1][1].x=cvRandInt(&rng) % width3 - width; pt[1][1].y=cvRandInt(&rng) % height3 - height; pt[1][2].x=cvRandInt(&rng) % width3 - width; pt[1][2].y=cvRandInt(&rng) % height3 - height;

cvPolyLine( image, pt, arr, 2, 1, random_color(&rng),

cvRandInt(&rng), line_type, 0 );//函数cvPolyLine 绘制一个简单的或多样的多角曲线

cvShowImage(wndname,image); cvWaitKey(DELAY); }

for (i = 0; i< NUMBER; i++) {

pt[0][0].x=cvRandInt(&rng) % width3 - width; pt[0][0].y=cvRandInt(&rng) % height3 - height; pt[0][1].x=cvRandInt(&rng) % width3 - width; pt[0][1].y=cvRandInt(&rng) % height3 - height; pt[0][2].x=cvRandInt(&rng) % width3 - width; pt[0][2].y=cvRandInt(&rng) % height3 - height; pt[1][0].x=cvRandInt(&rng) % width3 - width; pt[1][0].y=cvRandInt(&rng) % height3 - height; pt[1][1].x=cvRandInt(&rng) % width3 - width; pt[1][1].y=cvRandInt(&rng) % height3 - height; pt[1][2].x=cvRandInt(&rng) % width3 - width; pt[1][2].y=cvRandInt(&rng) % height3 - height;

cvFillPoly( image, pt, arr, 2, random_color(&rng), line_type, 0 );//函数cvFillPoly用于一个单独被多变形轮廓所限定的区域内进行填充 cvShowImage(wndname,image); cvWaitKey(DELAY); }

for (i = 0; i< NUMBER; i++) {

pt1.x=cvRandInt(&rng) % width3 - width; pt1.y=cvRandInt(&rng) % height3 - height;

cvCircle( image, pt1, cvRandInt(&rng)00, random_color(&rng), cvRandInt(&rng)-1, line_type, 0 );//函数cvCircle绘制或填充一个给定圆心和半径的圆 cvShowImage(wndname,image); cvWaitKey(DELAY); }

for (i = 1; i< NUMBER; i++) {

pt1.x=cvRandInt(&rng) % width3 - width; pt1.y=cvRandInt(&rng) % height3 - height;

cvInitFont( &font, cvRandInt(&rng) % 8, (cvRandInt(&rng)0)*0.05+0.1, (cvRandInt(&rng)0)*0.05+0.1,

(cvRandInt(&rng)%5)*0.1, cvRound(cvRandInt(&rng)),

line_type );//字体结构初始化。函数 cvRound, cvFloor, cvCeil 用一种舍入方法将输入浮点数转换成整数。 cvRound 返回和参数最接近的整数值

cvPutText( image, \Petroleum University!\pt1, &font, random_color(&rng));//在图像中加入文本 cvShowImage(wndname,image); cvWaitKey(DELAY); }

cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX, 3, 3, 0.0, 5, line_type );

cvGetTextSize( \设置字符串文本的宽度和高度

pt1.x = (width - text_size.width)/2; pt1.y = (height + text_size.height)/2; image2 = cvCloneImage(image);

for( i = 0; i < 255; i++ ) {

cvSubS( image2, cvScalarAll(i), image, 0 );//函数 cvSubS 从原数组的每个元素中减去一个数量

cvPutText( image, \CV_RGB(255,i,i));

cvShowImage(wndname,image); cvWaitKey(DELAY); }

// Wait for a key stroke; the same function arranges events processing cvWaitKey(0);

cvReleaseImage(&image); cvReleaseImage(&image2); cvDestroyWindow(wndname);

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库图像处理经典算法及OpenCV程序(2)在线全文阅读。

图像处理经典算法及OpenCV程序(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/336455.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: