OPENCV:我想在循环中绘制基本形状,每次绘制新形状时删除旧形状
我从opencv库中给出的shape.c中获取了代码,并对其进行了一些修改OPENCV:我想在循环中绘制基本形状,每次绘制新形状时删除旧形状,c,opencv,C,Opencv,我从opencv库中给出的shape.c中获取了代码,并对其进行了一些修改 #include <stdio.h> #include "cv.h" #include "highgui.h" int main(int argc, char** argv) { int i = 0; for(i=0;i<3 ;i++) { /* create an image */ IplImage *img = cvCreateImage(cvSize(20
#include <stdio.h>
#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv)
{
int i = 0;
for(i=0;i<3 ;i++)
{
/* create an image */
IplImage *img = cvCreateImage(cvSize(200, 100), IPL_DEPTH_8U, 3);
/* draw a green line */
cvLine(img, /* the dest image */
cvPoint(10 +i*10, 10), /* start point */
cvPoint(150, 80), /* end point */
cvScalar(0, 255, 0, 0), /* the color; green */
1, 8, 0); /* thickness, line type, shift */
/* draw a blue box */
cvRectangle(img, /* the dest image */
cvPoint(20, 15+i*10), /* top left point */
cvPoint(100, 70), /* bottom right point */
cvScalar(255, 0, 0, 0), /* the color; blue */
1, 8, 0); /* thickness, line type, shift */
/* draw a red circle */
cvCircle(img, /* the dest image */
cvPoint(110, 60), 35+i*10, /* center point and radius */
cvScalar(0, 0, 255, 0), /* the color; red */
1, 8, 0); /* thickness, line type, shift */
/* display the image */
cvNamedWindow("img", CV_WINDOW_AUTOSIZE);
cvShowImage("img", img);
cvWaitKey(0);
cvDestroyWindow("img");
cvReleaseImage(&img);
}
return 0;
}
#包括
#包括“cv.h”
#包括“highgui.h”
int main(int argc,字符**argv)
{
int i=0;
对于(i=0;i而言,没有直接的方法
初始化背景图像
在新克隆的背景图像上绘制前景形状
在克隆的背景图像上绘制另一个形状
一一展示
创建(空白)图像时,确保imageData干净的唯一方法是自己设置纯色。在cvCreateImage()
之后,调用cvSet()
如果删除窗口的创建/销毁不在循环中,则可以提高应用程序的性能。无需为每个新映像创建新窗口:
int i = 0;
cvNamedWindow("img", CV_WINDOW_AUTOSIZE);
for(i=0;i<3 ;i++)
{
// code
}
cvDestroyWindow("img");
inti=0;
cvNamedWindow(“img”,CV\u窗口\u自动调整大小);
对于(i=0;我可能不是你的问题,但你每次都在打开一个新窗口。
int i = 0;
cvNamedWindow("img", CV_WINDOW_AUTOSIZE);
for(i=0;i<3 ;i++)
{
// code
}
cvDestroyWindow("img");