资源简介
meanshift算法实现.rar
代码片段和文件信息
#include
bool selectobject = false;
int trackobject = 0;
cv::Rect selection;
cv::Mat image;
void onMouse( int event int x int y int void* ) {
static cv::Point origin;
if(selectobject) {
selection.x = MIN(x origin.x);
selection.y = MIN(y origin.y);
selection.width = std::abs(x - origin.x);
selection.height = std::abs(y - origin.y);
selection &= cv::Rect(0 0 image.cols image.rows);
}
switch(event) {
case CV_EVENT_LBUTTONDOWN:
origin = cv::Point(x y);
selection = cv::Rect(x y 0 0);
selectobject = true;
break;
case CV_EVENT_LBUTTONUP:
selectobject = false;
if( selection.width > 0 && selection.height > 0 )
trackobject = -1;
break;
}
}
int main( int argc const char** argv )
{
cv::VideoCapture video(“test_run.mp4“);
cv::namedWindow( “CamShift“ );
cv::setMouseCallback( “CamShift“ onMouse 0 );
cv::Mat frame hsv hue mask hist backproj;
cv::Rect trackWindow;
int hsize = 16;
float hranges[] = {0180};
const float* phranges = hranges;
while(true) {
video >> frame;
if( frame.empty() )
break;
frame.copyTo(image);
cv::cvtColor(image hsv cv::COLOR_BGR2HSV);
if( trackobject ) {
cv::inRange(hsv cv::Scalar(0 30 10) cv::Scalar(180 256 256) mask);
int ch[] = {0 0};
hue.create(hsv.size() hsv.depth());
cv::mixChannels(&hsv 1 &hue 1 ch 1);
if( trackobject < 0 ) {
cv::Mat roi(hue selection) maskroi(mask selection);
calcHist(&roi 1 0 maskroi hist 1 &hsize &phranges);
normalize(hist hist 0 255 CV_MINMAX);
trackWindow = selection;
trackobject = 1;
}
calcBackProject(&hue 1 0 hist backproj &phranges);
backproj &= mask;
cv::RotatedRect trackBox = CamShift(backproj trackWindow cv::TermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER 10 1 ));
if( trackWindow.area() <= 1 ) {
int cols = backproj.cols rows = backproj.rows r = (MIN(cols rows) + 5)/6;
trackWindow = cv::Rect(trackWindow.x - r trackWindow.y - r
trackWindow.x + r trackWindow.y + r) &
cv::Rect(0 0 cols rows);
}
ellipse( image trackBox cv::Scalar(00255) 3 CV_AA );
}
if( selectobject && selection.width > 0 && selection.height > 0 ) {
cv::Mat roi(image selection);
bitwise_not(roi roi);
}
imshow( “CamShift“ image );
char c = (char)cv::waitKey(1000/15.0);
if( c == 27 )
break;
}
cv
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3066 2018-06-17 10:14 main.cpp
----------- --------- ---------- ----- ----
3066 1
- 上一篇:智能变电站辅助监控系统解决方案
- 下一篇:迁移学习相关论文和个人总结
相关资源
- 换行插件.rar
- BC35.rar
- AnalysationofTrafficParaments.rar
- InvestigationofCar-speed.rar
- InvestigationofTrafficFlowing.rar
- vs2010破解版百度链接.rar
- 83390098XN297test.rar
- a4a957981f8dcf0175898b01a6478bfd.pdf
- 新建文本文档.txt59604
- 所有.txt
- 链接.zip
- 2019_全国大学生电子设计大赛_D题_简易
- 496782016年四川省TI杯大学生电子设计竞
- springboot.zip
- TIJ4-code.zip
- chrome.r39.crx
- pure_mathmodel_origin.slx
- pe_virus.rar
- wifi字典百度云链接.txt
- 微擎模块-人人商城.txt
- batcopyv2.0.zip
- 梯度下降法.zip
- 全国省市县.txt
- 基于深度学习的智能识别APP云盘链接
- opencv.rar
- zstp.txt
- workerman_gameMatch.zip
- hdl原理图和pcb联动设计.pdf
- 打造方猫眼项目前十章.txt
- BIGEMAP地图器_18@209548.exe.zip
评论
共有 条评论