码迷,mamicode.com
首页 > 其他好文 > 详细

Opencv角点检测

时间:2015-11-28 22:58:02      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

 

#include "stdafx.h"

#define max_corners 20

int main()
{
    int cornerNum = max_corners;
    vector<Point2f>corner;
    double qualityLevel = 0.05;
    double minDistance = 5;
    double scalar = 0.5;
    Mat srcImg,srcImg1;
    Mat grayImg,grayImg1,grayImg2;
    Mat disImg;
    int i;

    //VideoCapture video("E:\\C_VC_code\\Text_Photo\\feini.flv");
    VideoCapture video(0);
    if(!video.isOpened())
    {
        return -1;
    }
    video>>srcImg;
    resize(srcImg,srcImg1,Size(srcImg.cols*scalar,srcImg.rows*scalar),1,1,3);
    cvtColor(srcImg1,grayImg,CV_BGR2GRAY, 1);
    Rect rect;
    double up,down,left,right;
    while(1)
    {
        video>>srcImg;
        resize(srcImg,srcImg1,Size(srcImg.cols*scalar,srcImg.rows*scalar),1,1,3);
        //disImg = srcImg(Rect(200,150,130,130));
        cvtColor(srcImg1,grayImg1,CV_BGR2GRAY, 1);
        absdiff(grayImg1,grayImg,grayImg2);
        goodFeaturesToTrack(grayImg2,corner,cornerNum,qualityLevel,minDistance,Mat(),3,false,0.04);
        resize(srcImg,srcImg1,Size(srcImg.cols*scalar,srcImg.rows*scalar),1,1,3);
        cvtColor(srcImg1,grayImg,CV_BGR2GRAY, 1);
        up = left = 0x3f3f3f3f;
        down = right = -0x3f3f3f3f;

        for(i=0;i<corner.size();i++)
        {
            up = min(up, corner[i].y*1.0);
            left = min(left, corner[i].x*1.0);
            down = max(down, corner[i].y*1.0);
            right = max(right, corner[i].x*1.0);
            circle(srcImg1,Point(corner[i].x,corner[i].y),2,Scalar(0,255,0),2);
        }
        rect.x = left;
        rect.y = up;
        cout<< right<<" " <<down<<endl;
        rect.width = right-left;
        rect.height = up-down;

        rectangle(srcImg1,rect,Scalar(255,0,0),2);

        imshow("gray",grayImg2);
        imshow("x",srcImg1);
        
        if(waitKey(33)>0)
            break;
    }
    return 0;
}

 

Opencv角点检测

标签:

原文地址:http://www.cnblogs.com/mypsq/p/5003593.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!