分割移动微小物体
思路:
1. 前后兩幀相減,得到差分圖像
2.在差分圖像里求像素最大的點(最亮的點)
這樣就得到,移動微小物體
#include?"check.h"
#include?<iostream.h>????????????????????????????
void?main()
{
????DWORD?t1,t2;
????IplImage?*frame=0;
????CvCapture?*capture?=?cvCaptureFromAVI("E:\\跟蹤\\有源窄濾波片2m30fps_2.avi");
????CCheck?check;
????cvNamedWindow(?"目標跟蹤",?1?);//創建窗口
????frame?=?cvQueryFrame(capture);
????check.Init(frame);
????while(1)
????{
????????frame?=?cvQueryFrame(capture);
????????if(!frame)
????????{
????????????break;
????????}
????????t1?=?::GetTickCount();
????????CvPoint?point?=?check.point(frame);
????????IplImage?*show?=?cvCloneImage(?frame?);
????????cvCircle(show,?point,?10,?cvScalar(0,255,0),?2);
????????cvShowImage("目標跟蹤",show);
????????cvReleaseImage(?&show?);????
????????cvWaitKey(1);
????????t2?=?::GetTickCount();
????????cout?<<?t2-t1?<<?endl;
????}
????cvReleaseCapture(&capture);
????cvDestroyWindow("目標跟蹤");
}
#ifndef?CHECK_H
#define?CHECK_H
#include?"cv.h"
#include?"highgui.h"
#include?"cvcam.h"
#include?"check.h"
#define????_I8(image,x,y)????????(*((unsigned?char*)(image)->imageData+(image)->widthStep*(y)+(x)))????//直接調用圖像的像素,x、y為整數(圖像數據應為32F)
#define????_I32(img,x,y)?((float*)((img)->imageData?+?(img)->widthStep*(y)))[(x)]
class?CCheck
{
private:
????int?px,py;
????int?width,height;
????IplImage?*frame1;????//當前幀
????IplImage?*frame2;????//前一幀
public:
????CCheck();
????~CCheck();
????void????Init(IplImage?*img);
????CvPoint????point(IplImage?*img);
};
#endif
#include?"check.h"
#include?<iostream.h>????????????????????????????
void?main()
{
????DWORD?t1,t2;
????IplImage?*frame=0;
????CvCapture?*capture?=?cvCaptureFromAVI("E:\\跟蹤\\有源窄濾波片2m30fps_2.avi");
????CCheck?check;
????cvNamedWindow(?"目標跟蹤",?1?);//創建窗口
????frame?=?cvQueryFrame(capture);
????check.Init(frame);
????while(1)
????{
????????frame?=?cvQueryFrame(capture);
????????if(!frame)
????????{
????????????break;
????????}
????????t1?=?::GetTickCount();
????????CvPoint?point?=?check.point(frame);
????????IplImage?*show?=?cvCloneImage(?frame?);
????????cvCircle(show,?point,?10,?cvScalar(0,255,0),?2);
????????cvShowImage("目標跟蹤",show);
????????cvReleaseImage(?&show?);????
????????cvWaitKey(1);
????????t2?=?::GetTickCount();
????????cout?<<?t2-t1?<<?endl;
????}
????cvReleaseCapture(&capture);
????cvDestroyWindow("目標跟蹤");
}
1. 前后兩幀相減,得到差分圖像
2.在差分圖像里求像素最大的點(最亮的點)
這樣就得到,移動微小物體
#include?"check.h"
#include?<iostream.h>????????????????????????????
void?main()
{
????DWORD?t1,t2;
????IplImage?*frame=0;
????CvCapture?*capture?=?cvCaptureFromAVI("E:\\跟蹤\\有源窄濾波片2m30fps_2.avi");
????CCheck?check;
????cvNamedWindow(?"目標跟蹤",?1?);//創建窗口
????frame?=?cvQueryFrame(capture);
????check.Init(frame);
????while(1)
????{
????????frame?=?cvQueryFrame(capture);
????????if(!frame)
????????{
????????????break;
????????}
????????t1?=?::GetTickCount();
????????CvPoint?point?=?check.point(frame);
????????IplImage?*show?=?cvCloneImage(?frame?);
????????cvCircle(show,?point,?10,?cvScalar(0,255,0),?2);
????????cvShowImage("目標跟蹤",show);
????????cvReleaseImage(?&show?);????
????????cvWaitKey(1);
????????t2?=?::GetTickCount();
????????cout?<<?t2-t1?<<?endl;
????}
????cvReleaseCapture(&capture);
????cvDestroyWindow("目標跟蹤");
}
#ifndef?CHECK_H
#define?CHECK_H
#include?"cv.h"
#include?"highgui.h"
#include?"cvcam.h"
#include?"check.h"
#define????_I8(image,x,y)????????(*((unsigned?char*)(image)->imageData+(image)->widthStep*(y)+(x)))????//直接調用圖像的像素,x、y為整數(圖像數據應為32F)
#define????_I32(img,x,y)?((float*)((img)->imageData?+?(img)->widthStep*(y)))[(x)]
class?CCheck
{
private:
????int?px,py;
????int?width,height;
????IplImage?*frame1;????//當前幀
????IplImage?*frame2;????//前一幀
public:
????CCheck();
????~CCheck();
????void????Init(IplImage?*img);
????CvPoint????point(IplImage?*img);
};
#endif
#include?"check.h"
#include?<iostream.h>????????????????????????????
void?main()
{
????DWORD?t1,t2;
????IplImage?*frame=0;
????CvCapture?*capture?=?cvCaptureFromAVI("E:\\跟蹤\\有源窄濾波片2m30fps_2.avi");
????CCheck?check;
????cvNamedWindow(?"目標跟蹤",?1?);//創建窗口
????frame?=?cvQueryFrame(capture);
????check.Init(frame);
????while(1)
????{
????????frame?=?cvQueryFrame(capture);
????????if(!frame)
????????{
????????????break;
????????}
????????t1?=?::GetTickCount();
????????CvPoint?point?=?check.point(frame);
????????IplImage?*show?=?cvCloneImage(?frame?);
????????cvCircle(show,?point,?10,?cvScalar(0,255,0),?2);
????????cvShowImage("目標跟蹤",show);
????????cvReleaseImage(?&show?);????
????????cvWaitKey(1);
????????t2?=?::GetTickCount();
????????cout?<<?t2-t1?<<?endl;
????}
????cvReleaseCapture(&capture);
????cvDestroyWindow("目標跟蹤");
}
轉載于:https://www.cnblogs.com/wqj1212/archive/2007/12/21/1009689.html
總結
- 上一篇: STM32汉字字模制作详解(OLED实战
- 下一篇: java有哪些练手的项目