opencv帮我看看怎么这样呢,轮廓无法读出来
2013-08-20 18:54
344 查看
我最近呢,正在做运动识别跟踪程序,用opencv想着把运动目标提取出来加上轮廓求质心呢,结果有错误。
#include"cv.h"
#include"highgui.h"
#include "cxcore.h"
#include <D:\opencv\opencv\build\include\opencv2\legacy\legacy.hpp>
using namespace std;
using namespace cv;
IplImage* doCanny(IplImage* in,
double lowThresh,
double highThresh,
double aperture);
int main(int argc,char** argv)
{
cvNamedWindow("trace",CV_WINDOW_AUTOSIZE);
cvNamedWindow("fore",CV_WINDOW_AUTOSIZE);
CvCapture* capture=cvCreateFileCapture("bike.avi");
IplImage* frame1;
IplImage* curr=NULL;//use to store the first image
IplImage* next=NULL;//use to store the second image
IplImage* fore=NULL;//use to store the diversity between the first and the second image
IplImage* result=NULL;
IplImage* result1=NULL;
IplImage* result2=NULL;
IplImage* img2=NULL;
IplImage* img3=NULL;
double fps=cvGetCaptureProperty(capture,CV_CAP_PROP_FPS);
int frames=(int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_COUNT);
int flag=0;
while(frames>60)
{
//first should get the first image from the video
frame1=cvQueryFrame(capture);
curr=cvQueryFrame(capture);
flag++;
if(flag==1)
{
next=cvCreateImage(cvGetSize(curr),8,3);
fore=cvCreateImage(cvGetSize(curr),8,3);
result=cvCreateImage(cvGetSize(curr),8,3);
result1=cvCreateImage(cvGetSize(curr),8,3);
result2=cvCreateImage(cvGetSize(curr),8,3);
cvCopyImage(curr,next);//set the next is current iamge
}
else
{
cvAbsDiff(curr,next,fore);
//增加对于差图的处理
cvSmooth(fore,result,CV_GAUSSIAN,3,3);//delete some noise
CvMemStorage* storage=cvCreateMemStorage(0);//apply new store space
CvSeq* comp=0;
cvPyrSegmentation(result,result1,storage,&comp,4,200,50);
int n_comp=comp->total;//get the connected area number,we hope is 1,if not equals 1 we will use the Dilate
img3=cvCreateImage(cvGetSize(curr),8,3);
cvThreshold(result1,result2, 60, 255, CV_THRESH_BINARY);
cvDilate(result2,img3,NULL,2);
int mode=CV_RETR_EXTERNAL;
cvFindContours(img3,storage,&comp,sizeof(CvContour),mode,CV_CHAIN_APPROX_SIMPLE);//一到这里就出问题了,编译无错误,运行出现错误了
int i;
for(i=1;comp!=0;comp->h_next)
{//get the area
double area=fabs(cvContourArea(comp,CV_WHOLE_SEQ));
CvScalar color = CV_RGB(i, rand()&255, rand()&255);
cvDrawContours(img3, comp, color, color, -1, CV_FILLED, 8 );
i++; // label递增
}
// img3=doCanny(img2,10.0,100,3);//make a canny detect
cvShowImage("trace",frame1);
cvShowImage("fore",img3);
char s=cvWaitKey(33);
if(s==27) break;
frames--;
}
}
cvReleaseCapture(&capture);
cvDestroyWindow("fore");
cvDestroyWindow("trace");
return(0);
}
#include"cv.h"
#include"highgui.h"
#include "cxcore.h"
#include <D:\opencv\opencv\build\include\opencv2\legacy\legacy.hpp>
using namespace std;
using namespace cv;
IplImage* doCanny(IplImage* in,
double lowThresh,
double highThresh,
double aperture);
int main(int argc,char** argv)
{
cvNamedWindow("trace",CV_WINDOW_AUTOSIZE);
cvNamedWindow("fore",CV_WINDOW_AUTOSIZE);
CvCapture* capture=cvCreateFileCapture("bike.avi");
IplImage* frame1;
IplImage* curr=NULL;//use to store the first image
IplImage* next=NULL;//use to store the second image
IplImage* fore=NULL;//use to store the diversity between the first and the second image
IplImage* result=NULL;
IplImage* result1=NULL;
IplImage* result2=NULL;
IplImage* img2=NULL;
IplImage* img3=NULL;
double fps=cvGetCaptureProperty(capture,CV_CAP_PROP_FPS);
int frames=(int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_COUNT);
int flag=0;
while(frames>60)
{
//first should get the first image from the video
frame1=cvQueryFrame(capture);
curr=cvQueryFrame(capture);
flag++;
if(flag==1)
{
next=cvCreateImage(cvGetSize(curr),8,3);
fore=cvCreateImage(cvGetSize(curr),8,3);
result=cvCreateImage(cvGetSize(curr),8,3);
result1=cvCreateImage(cvGetSize(curr),8,3);
result2=cvCreateImage(cvGetSize(curr),8,3);
cvCopyImage(curr,next);//set the next is current iamge
}
else
{
cvAbsDiff(curr,next,fore);
//增加对于差图的处理
cvSmooth(fore,result,CV_GAUSSIAN,3,3);//delete some noise
CvMemStorage* storage=cvCreateMemStorage(0);//apply new store space
CvSeq* comp=0;
cvPyrSegmentation(result,result1,storage,&comp,4,200,50);
int n_comp=comp->total;//get the connected area number,we hope is 1,if not equals 1 we will use the Dilate
img3=cvCreateImage(cvGetSize(curr),8,3);
cvThreshold(result1,result2, 60, 255, CV_THRESH_BINARY);
cvDilate(result2,img3,NULL,2);
int mode=CV_RETR_EXTERNAL;
cvFindContours(img3,storage,&comp,sizeof(CvContour),mode,CV_CHAIN_APPROX_SIMPLE);//一到这里就出问题了,编译无错误,运行出现错误了
int i;
for(i=1;comp!=0;comp->h_next)
{//get the area
double area=fabs(cvContourArea(comp,CV_WHOLE_SEQ));
CvScalar color = CV_RGB(i, rand()&255, rand()&255);
cvDrawContours(img3, comp, color, color, -1, CV_FILLED, 8 );
i++; // label递增
}
// img3=doCanny(img2,10.0,100,3);//make a canny detect
cvShowImage("trace",frame1);
cvShowImage("fore",img3);
char s=cvWaitKey(33);
if(s==27) break;
frames--;
}
}
cvReleaseCapture(&capture);
cvDestroyWindow("fore");
cvDestroyWindow("trace");
return(0);
}
相关文章推荐
- 请问,这样的错误该怎么处理,按照网上的配置好了,可是一直不成功,LINK : fatal error LNK1104: 无法打开文件“opencv_world331.lib”请问,这样的错误该怎么处理
- 各位大牛帮忙看看问题出来哪?自己实现一个数组模板类,编译无法通过
- to dudu:麻烦给我看看,怎么界面成这样了啊?
- 我Turbo C 2.0这样运行出来怎么是空白阿
- 检测出来的结果怎么会是这样。。
- 在网上看到这样一张图片给大家分享出来看看
- ”标准答案没出来,我怎么知道我想表达什么?……“这样的话,根本就不仅仅是笑话,而且还是现实
- oracle数据库表中,某个字段是varchar2类型的但其实存的是数字,这样安装该字段排序,排出来的顺序是不对的,sql语句怎么写就可以排序了?
- 急求!vs10+opencv,如何在一张二值图中找出二维码的轮廓并提取出来然后进行识别啊?!
- 最近在找新工作,今天收到这样的一封Email,贴出来让大家看看!
- 怎么看地图?还是要一起看看地图是怎么画出来的!
- OpenCV中Mat-哪位大虾帮忙看看,怎么老是报错啊
- 关于怎么解决opencv无法显示图片的解决办法
- 兄弟mfc-7220如何取消打印报告?不管是接收还是发送传真,都打印报告出来,这样浪费一张白纸,怎么去掉?
- ③②①像这样的数字10以上的怎么搞出来
- 搞不懂啊,为什么会这样,连结果都输不出来,怎么就AC了呢?
- eclipse里用jad反编译class后出现这样是怎么回事????急急!!!!各位大侠看看啊
- 检测出来的结果怎么会是这样。。
- 看看这些图片、这样怎么识别呢?
- 大家看看这个是怎么出来的...