疑似小米3真机曝光 看小米手机酷玩激光虚拟键盘
//unsigned int frameNumber = 0;
unsigned int blobNumber = 0;
bool quit = false;
while (!quit&&cvGrabFrame(capture))
{
IplImage *img = cvRetrieveFrame(capture);
cvConvertScale(img, frame, 1, 0);
IplImage *segmentated = cvCreateImage(imgSize, 8, 1);
// Detecting red pixels:
// (This is very slow, use direct access better...)
for (unsigned int j=0; j<imgSize.height; j++)
for (unsigned int i=0; i<imgSize.width; i++)
{
CvScalar c = cvGet2D(frame, j, i);
double b = ((double)c.val[0])/255.;
double g = ((double)c.val[1])/255.;
double r = ((double)c.val[2])/255.;
// unsigned char f = 255*((r>0.2+g)&&(r>0.2+b));
// cvSet2D(segmentated, j, i, CV_RGB(f, f, f));
if(b>0.4 || g>0.4 || r>0.4)
cvSet2D(segmentated, j, i, CV_RGB(255, 255, 255));
else
cvSet2D(segmentated, j, i, CV_RGB(0, 0, 0));
}
cvMorphologyEx(segmentated, segmentated, NULL, morphKernel, CV_MOP_OPEN, 1);
cvShowImage("segmentated", segmentated);
IplImage *labelImg = cvCreateImage(cvGetSize(frame), IPL_DEPTH_LABEL, 1);
CvBlobs blobs;
unsigned int result = cvLabel(segmentated, labelImg, blobs);
cvFilterByArea(blobs, 500, 1000000);
cvRenderBlobs(labelImg, blobs, frame, frame, CV_BLOB_RENDER_BOUNDING_BOX);
cvUpdateTracks(blobs, tracks, 200., 5);
cvRenderTracks(tracks, frame, frame, CV_TRACK_RENDER_ID|CV_TRACK_RENDER_BOUNDING_BOX);
cvShowImage("red_object_tracking", frame);
// print key
for (CvTracks::const_iterator it=tracks.begin(); it!=tracks.end(); ++it)
{
int xx = (int)it->second->centroid.x;
int yy = (int)it->second->centroid.y;
//std::cout << xx << ',' << yy << std::endl;
图片新闻
发表评论
请输入评论内容...
请输入评论/评论长度6~500个字
暂无评论
暂无评论