矩形放大到源图像重新检测

	//放大图像,在周围检测人体
			int x = m_trajectories[i].object->particles[0].x;
			int y = m_trajectories[i].object->particles[0].y;
			int w = cvRound(m_trajectories[i].object->particles[0].width*f_scale);//f_scale矩形膨胀系数
			int h = cvRound(m_trajectories[i].object->particles[0].height*f_scale);

			int x1 = std::max(x-w/2,0);
			int y1 = std::max(y-h/2,0);
			int x2 = std::min(x+w/2,frameSrc->width);
			int y2 = std::min(y+h/2,frameSrc->height);
			w = (x2-x1)*scale;//scale图像缩放系数
			h = (y2-y1)*scale;
			x = x1*scale;
			y = y1*scale;

			imageDet = cvCreateImage(cvSize(w,h),8,1);
			cvSetImageROI(frameSrc,cvRect(x,y,w,h));
			cvCopy(frameSrc,imageDet); 
			cvResetImageROI(frameSrc);
			vector<Rect> found;
 			people_dectect_hog.detectMultiScale(imageDet, found, 0, Size(8, 8), Size(32, 32), 1.05, 2);//行人检测
			if (found.size()!=0)
			{
				for(int j = 0; j <found.size(); j++)
				{
					Rect r = found[0];
					r.x = cvRound((r.x+r.width*0.1+x)/scale);//+x-w;
					r.width = cvRound((r.width*0.8)/scale);
					r.y = cvRound((r.y+r.height*0.07+y)/scale);//+y-h;
					r.height = cvRound((r.height*0.8)/scale);
					cvRectangle(frameHSV, r.tl(), r.br(), Scalar(0, 255, 0), 2);
				}
				cvWaitKey(10);
				cvShowImage("image",frameHSV);
				cvWaitKey(0);
			}

你可能感兴趣的:(矩形放大到源图像重新检测)