精华内容
下载资源
问答
  • OpenCV检测矩形

    千次阅读 2019-04-22 12:52:44
    代码来自... #ifdef _CH_ #pragma package <opencv> #endif #ifndef _EiC #include "cv.h" #include "highgui.h" #include <stdio.h> #include <math.h> #include <string.h&g...

    代码来自www.opencvchina.com 

    #ifdef _CH_
    #pragma package <opencv>
    #endif
    
    #ifndef _EiC
    #include "cv.h"
    #include "highgui.h"
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    #endif
    
    int thresh = 50;
    IplImage* img = 0;
    IplImage* img0 = 0;
    CvMemStorage* storage = 0;
    CvPoint pt[4];
    const char* wndname = "Square Detection Demo";
    
    // helper function:
    // finds a cosine of angle between vectors
    // from pt0->pt1 and from pt0->pt2 
    double angle( CvPoint* pt1, CvPoint* pt2, CvPoint* pt0 )
    {
        double dx1 = pt1->x - pt0->x;
        double dy1 = pt1->y - pt0->y;
        double dx2 = pt2->x - pt0->x;
        double dy2 = pt2->y - pt0->y;
        return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);
    }
    
    // returns sequence of squares detected on the image.
    // the sequence is stored in the specified memory storage
    CvSeq* findSquares4( IplImage* img, CvMemStorage* storage )
    {
        CvSeq* contours;
        int i, c, l, N = 11;
        CvSize sz = cvSize( img->width & -2, img->height & -2 );
        IplImage* timg = cvCloneImage( img ); // make a copy of input image
        IplImage* gray = cvCreateImage( sz, 8, 1 ); 
        IplImage* pyr = cvCreateImage( cvSize(sz.width/2, sz.height/2), 8, 3 );
        IplImage* tgray;
        CvSeq* result;
        double s, t;
        // create empty sequence that will contain points -
        // 4 points per square (the square's vertices)
        CvSeq* squares = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvPoint), storage );
        
        // select the maximum ROI in the image
        // with the width and height divisible by 2
        cvSetImageROI( timg, cvRect( 0, 0, sz.width, sz.height ));
        
        // down-scale and upscale the image to filter out the noise
        cvPyrDown( timg, pyr, 7 );
        cvPyrUp( pyr, timg, 7 );
        tgray = cvCreateImage( sz, 8, 1 );
        
        // find squares in every color plane of the image
        for( c = 0; c < 3; c++ )
        {
            // extract the c-th color plane
            cvSetImageCOI( timg, c+1 );
            cvCopy( timg, tgray, 0 );
            
            // try several threshold levels
            for( l = 0; l < N; l++ )
            {
                // hack: use Canny instead of zero threshold level.
                // Canny helps to catch squares with gradient shading   
                if( l == 0 )
                {
                    // apply Canny. Take the upper threshold from slider
                    // and set the lower to 0 (which forces edges merging) 
                    cvCanny( tgray, gray, 0, thresh, 5 );
                    // dilate canny output to remove potential
                    // holes between edge segments 
                    cvDilate( gray, gray, 0, 1 );
                }
                else
                {
                    // apply threshold if l!=0:
                    //     tgray(x,y) = gray(x,y) < (l+1)*255/N ? 255 : 0
                    cvThreshold( tgray, gray, (l+1)*255/N, 255, CV_THRESH_BINARY );
                }
                
                // find contours and store them all as a list
                cvFindContours( gray, storage, &contours, sizeof(CvContour),
                    CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
                
                // test each contour
                while( contours )
                {
                    // approximate contour with accuracy proportional
                    // to the contour perimeter
                    result = cvApproxPoly( contours, sizeof(CvContour), storage,
                        CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.02, 0 );
                    // square contours should have 4 vertices after approximation
                    // relatively large area (to filter out noisy contours)
                    // and be convex.
                    // Note: absolute value of an area is used because
                    // area may be positive or negative - in accordance with the
                    // contour orientation
                    if( result->total == 4 &&
                        fabs(cvContourArea(result,CV_WHOLE_SEQ)) > 1000 &&
                        cvCheckContourConvexity(result) )
                    {
                        s = 0;
                        
                        for( i = 0; i < 5; i++ )
                        {
                            // find minimum angle between joint
                            // edges (maximum of cosine)
                            if( i >= 2 )
                            {
                                t = fabs(angle(
                                (CvPoint*)cvGetSeqElem( result, i ),
                                (CvPoint*)cvGetSeqElem( result, i-2 ),
                                (CvPoint*)cvGetSeqElem( result, i-1 )));
                                s = s > t ? s : t;
                            }
                        }
                        
                        // if cosines of all angles are small
                        // (all angles are ~90 degree) then write quandrange
                        // vertices to resultant sequence 
                        if( s < 0.3 )
                            for( i = 0; i < 4; i++ )
                                cvSeqPush( squares,
                                    (CvPoint*)cvGetSeqElem( result, i ));
                    }
                    
                    // take the next contour
                    contours = contours->h_next;
                }
            }
        }
        
        // release all the temporary images
        cvReleaseImage( &gray );
        cvReleaseImage( &pyr );
        cvReleaseImage( &tgray );
        cvReleaseImage( &timg );
        
        return squares;
    }
    
    
    // the function draws all the squares in the image
    void drawSquares( IplImage* img, CvSeq* squares )
    {
        CvSeqReader reader;
        IplImage* cpy = cvCloneImage( img );
        int i;
        
        // initialize reader of the sequence
        cvStartReadSeq( squares, &reader, 0 );
        
        // read 4 sequence elements at a time (all vertices of a square)
        for( i = 0; i < squares->total; i += 4 )
        {
            CvPoint* rect = pt;
            int count = 4;
            
            // read 4 vertices
            memcpy( pt, reader.ptr, squares->elem_size );
            CV_NEXT_SEQ_ELEM( squares->elem_size, reader );
            memcpy( pt + 1, reader.ptr, squares->elem_size );
            CV_NEXT_SEQ_ELEM( squares->elem_size, reader );
            memcpy( pt + 2, reader.ptr, squares->elem_size );
            CV_NEXT_SEQ_ELEM( squares->elem_size, reader );
            memcpy( pt + 3, reader.ptr, squares->elem_size );
            CV_NEXT_SEQ_ELEM( squares->elem_size, reader );
            
            // draw the square as a closed polyline 
            cvPolyLine( cpy, &rect, &count, 1, 1, CV_RGB(0,255,0), 3, CV_AA, 0 );
        }
        
        // show the resultant image
        cvShowImage( wndname, cpy );
        cvReleaseImage( &cpy );
    }
    
    
    void on_trackbar( int a )
    {
        if( img )
            drawSquares( img, findSquares4( img, storage ) );
    }
    
    char* names[] = { "pic1.png", "pic2.png", "pic3.png",
                      "pic4.png", "pic5.png", "pic6.png", 0 };
    
    int main(int argc, char** argv)
    {
        int i, c;
        // create memory storage that will contain all the dynamic data
        storage = cvCreateMemStorage(0);
    
        for( i = 0; names != 0; i++ )
        {
            // load i-th image
            img0 = cvLoadImage( names, 1 );
            if( !img0 )
            {
                printf("Couldn't load %s\n", names );
                continue;
            }
            img = cvCloneImage( img0 );
            
            // create window and a trackbar (slider) with parent "image" and set callback
            // (the slider regulates upper threshold, passed to Canny edge detector) 
            cvNamedWindow( wndname, 1 );
            cvCreateTrackbar( "canny thresh", wndname, &thresh, 1000, on_trackbar );
            
            // force the image processing
            on_trackbar(0);
            // wait for key.
            // Also the function cvWaitKey takes care of event processing
            c = cvWaitKey(0);
            // release both images
            cvReleaseImage( &img );
            cvReleaseImage( &img0 );
            // clear memory storage - reset free space position
            cvClearMemStorage( storage );
            if( c == 27 )
                break;
        }
        
        cvDestroyWindow( wndname );
        
        return 0;
    }
    
    #ifdef _EiC
    main(1,"squares.c");
    #endif

     

    展开全文
  • 检测矩形 用java opencv检测矩形
  • OPENCV检测矩形并计算其中心

    千次阅读 2014-10-27 18:28:46
    const char * wndname = "正方形检测 demo";   //angle函数用来返回(两个向量之间找到角度的余弦值) double angle( CvPoint* pt1, CvPoint* pt2, CvPoint* pt0 ) {  double dx1 = pt1->x - pt0->x...
    #include "cv.h"  
    
    #include "highgui.h"  
    #include <stdio.h>  
    #include <math.h>  
    #include <string.h>  
      
    #pragma comment(lib, "cv.lib")  
    #pragma comment(lib, "cxcore.lib")  
    #pragma comment(lib, "highgui.lib")  
      


        
    IplImage* img =NULL;  
    IplImage* img0 = NULL;  
    CvMemStorage* storage =NULL;  
    const char * wndname = "正方形检测 demo";  
      
    //angle函数用来返回(两个向量之间找到角度的余弦值)  
    double angle( CvPoint* pt1, CvPoint* pt2, CvPoint* pt0 )  
    {  
     double dx1 = pt1->x - pt0->x;  
     double dy1 = pt1->y - pt0->y;  
     double dx2 = pt2->x - pt0->x;  
     double dy2 = pt2->y - pt0->y;  
     return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);  
    }  
      
    // 返回图像中找到的所有轮廓序列,并且序列存储在内存存储器中  
      
    CvSeq* findSquares4( IplImage* img, CvMemStorage* storage )  
    {  
     CvSeq* contours;  
     int i, l, N = 11;  
      
       
     //IplImage* timg = cvCloneImage( img );  
     //IplImage* gray = cvCreateImage( sz, 8, 1 );  
     //IplImage* pyr = cvCreateImage( cvSize(sz.width/2, sz.height/2), 8, 1 );  


     CvSeq* result;  
     double s, t;  
     // 创建一个空序列用于存储轮廓角点  
     CvSeq* squares = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvPoint), storage );  
      

      // 尝试各种阈值提取得到的(N=11)  
      for( l = 0; l < N; l++ )  
      {  
       // apply Canny. Take the upper threshold from slider  
       // Canny helps to catch squares with gradient shading    
       if( l == 0 )  
       {  
      
    cvCanny( img, img, 100,255, 3 );  //正常情况下
        //使用任意结构元素膨胀图像  
        cvDilate( img, img, 0, 1 );  
       }  
       else  
       {  
        // apply threshold if l!=0:  
        cvThreshold( img, img, (l+1)*255/N, 255, CV_THRESH_BINARY );  
       }  
      
       // 找到所有轮廓并且存储在序列中  
       cvFindContours( img, storage, &contours, sizeof(CvContour),  
        CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );  
      
       // 遍历找到的每个轮廓contours  
       while( contours )  
       {  
         //用指定精度逼近多边形曲线  
        result = cvApproxPoly( contours, sizeof(CvContour), storage,  
         CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.02, 0 );  
                        
      
        if( result->total == 4 &&  
         fabs(cvContourArea(result,CV_WHOLE_SEQ)) > 500 &&  
         fabs(cvContourArea(result,CV_WHOLE_SEQ)) < 1000000 &&  
         cvCheckContourConvexity(result) )  
        {  
         s = 0;  
      
         for( i = 0; i < 5; i++ )  
         {  
          // find minimum angle between joint edges (maximum of cosine)  
          if( i >= 2 )  
          {  
           t = fabs(angle(  
            (CvPoint*)cvGetSeqElem( result, i ),  
            (CvPoint*)cvGetSeqElem( result, i-2 ),  
            (CvPoint*)cvGetSeqElem( result, i-1 )));  
           s = s > t ? s : t;  
          }  
         }  
      
         // if 余弦值 足够小,可以认定角度为90度直角  
         //cos0.1=83度,能较好的趋近直角  
         if( s < 0.1 )    
          for( i = 0; i < 4; i++ )  
           cvSeqPush( squares,  
           (CvPoint*)cvGetSeqElem( result, i ));  
        }  
      
        // 继续查找下一个轮廓  
        contours = contours->h_next;  
       }  
      }  
      
      
     return squares;  
    }  
      
    //drawSquares函数用来画出在图像中找到的所有正方形轮廓  
    void drawSquares( IplImage* img, CvSeq* squares )  
    {  
     CvSeqReader reader; 
     CvPoint pt3;
     IplImage* cpy = cvCloneImage( img );  
     int i;  
     cvStartReadSeq( squares, &reader, 0 );  
      
     // read 4 sequence elements at a time (all vertices of a square)  
     for( i = 0; i < squares->total; i += 4 )  
     {  
      CvPoint pt[4], *rect = pt;  
      int count = 4;  
      
      // read 4 vertices  
      CV_READ_SEQ_ELEM( pt[0], reader );  
      CV_READ_SEQ_ELEM( pt[1], reader );  
      CV_READ_SEQ_ELEM( pt[2], reader );  
      CV_READ_SEQ_ELEM( pt[3], reader );
      pt3.x=(pt[0].x+pt[1].x+pt[2].x+pt[3].x)/4;
      pt3.y=(pt[0].y+pt[1].y+pt[2].y+pt[3].y)/4;
      cvLine(cpy,pt3,pt3,CV_RGB(255, 255, 255),4,8,0);
      printf("(%d,%d)",pt3.x,pt3.y);
      
      // draw the square as a closed polyline  
      cvPolyLine( cpy, &rect, &count, 1, 1, CV_RGB(255,255,255), 2, CV_AA, 0 );  
     }  
      
     cvShowImage( wndname, cpy );  
     cvReleaseImage( &cpy );  
    }  
      
        
      
    int main(int argc, char** argv)  
    {  
      
     storage = cvCreateMemStorage(0);  
      
      
      img0 = cvLoadImage( "000.jpg", 0 );  
      
      img = cvCloneImage( img0 );  
      cvNamedWindow( wndname, 1 );  
      
      // find and draw the squares  
      drawSquares( img, findSquares4( img, storage ) );  
      
      cvWaitKey(0);  
        
      cvReleaseImage( &img );  
      cvReleaseImage( &img0 );  
      
      cvClearMemStorage( storage );  
      
     cvDestroyWindow( wndname );  


    }  
    展开全文
  • opencv实现矩形检测

    2020-12-17 09:31:18
    本文实例为大家分享了opencv实现矩形检测的具体代码,供大家参考,具体内容如下 #include "cv.h" #include "highgui.h" #include #include <math.h> #include ///////////////////////////////////////////...
  • opencv矩形检测

    2015-07-08 18:02:29
    利用opencv完成矩形检测的功能,可以在各种需要的场合使用,自己码的程序。opencv2.4.9 vs2012
  • OpenCV矩形检测

    2014-07-23 17:47:29
    利用OpenCV对图像中的矩形对象进行检测的代码
  • OpenCV检测正方形、矩形源代码。循环读取多副图像,过滤噪音,遍历找到的每个轮廓,检测所有矩形轮廓(稍作改动可以只检测一副图中的矩形)。
  • 利用opencv检测矩形

    千次阅读 2016-03-15 16:18:31
    利用opencv和c++语言来检测矩形轮廓并且返回矩形的顶点坐标

    利用opencv和c++语言来检测出矩形轮廓并且返回矩形的顶点坐标

    #pragma once
    #include "TROOT.h"
    #include "CBinToProfile.h"
    #include "TH1.h"
    #include "CBmpDiff.h"
    #include "CCircleToPeak.h"
    #include "CColorCut.h"
    #include "CCubicBSpline.h"
    #include "CCurveAngle.h"
    #include "CEdgeHit.h"
    #include "CEdgeHitChain.h"
    #include "CEdgeToCircleChain.h"
    #include "CEdgeToFloat.h"
    #include "CFloatMatch.h"
    #include "CFrame.h"
    #include "CIntProfileToFloat.h"
    #include "CLBP.h"
    #include "CLine.h"
    #include "CLinePara.h"
    #include "CNormToPeak.h"
    #include "CPicToBin.h"
    #include "CPicToEdge.h"
    #include "CPointProjection.h"
    #include "CPointToCircle.h"
    #include "CPointToNorm.h"
    #include "CPointToPeak.h"
    #include "CProfile.h"
    #include "CRegionMatch.h"
    #include "CSixSword.h"
    #include "CTime.h"
    #include "lib.h"
    #include "vlib.h"
    #include "paras.h"
    #include "spline.h"
    #include <opencv2/opencv.hpp>
    #include <iostream>
    #include <windows.h>
    
    using namespace cv;
    using namespace std;
    
    void setFrame(VideoCapture cap, double w, double h)
    {
        cap.set(CV_CAP_PROP_FRAME_WIDTH, w);
        cap.set(CV_CAP_PROP_FRAME_HEIGHT, h);
    }
    
    CvMemStorage* storage;//CvMemStorage 动态内存存储及操作函数
    CvMemStorage* tempStorage;
    void initStorage()//初始化内存空间
    {
        storage = cvCreateMemStorage(0);//分配内存空间
        tempStorage = cvCreateMemStorage(0);
    }
    void releaseStorage()//释放内存空间
    {
        cvReleaseMemStorage (&storage);
        cvReleaseMemStorage (&tempStorage);
    }
    
    CvSeq* tempContour;
    CvSeqWriter  writer;
    CEdgeHit *tempHit;
    CvPoint tempPoint;
    
    CvSeq* transform(CEdgeHitChain chain)//自定义的transform函数
    {
        tempContour = cvCreateSeq(CV_SEQ_POLYGON, sizeof(CvSeq), sizeof(CvPoint), tempStorage);//创建序列
        cvStartAppendToSeq( tempContour, &writer );//序列写入操作把temppoint写入tempContour
    
        tempHit = chain.first;
        while (tempHit!=chain.last)
        {
            tempPoint.x = tempHit->x;
            tempPoint.y = tempHit->y;
            CV_WRITE_SEQ_ELEM( tempPoint, writer );//通过循环把tempPoint全部写入writer
            tempHit = tempHit->next;
        }
        return tempContour;//返回轮廓
    }
    
    // angle函数用来返回(两个向量之间找到角度的余弦值)勾股定理
    double angle(CvPoint* pt1, CvPoint* pt2, CvPoint* pt0)
    {
        double dx1 = pt1->x - pt0->x;
        double dy1 = pt1->y - pt0->y;
        double dx2 = pt2->x - pt0->x;
        double dy2 = pt2->y - pt0->y;
        return (dx1*dx2 + dy1*dy2) / sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);
    }
    
    int main(int argc, char *argv[])
    {
        int c;
        printf("welcome!\n");
        VideoCapture cap_1;
        cap_1.open(0);
        if (!cap_1.isOpened())
        {
            printf("摄像头1打开失败!\n");
            return -1;
        }
        double w = 320, h = 320;
        setFrame(cap_1, w, h);
    
        Mat frame_1;
        IplImage* image_1;
        IplImage* gray;
        CvSize sz;
        CSixSword tc;
    
        CvSeq* contour;
        CvSeq* result;
        CvSeq* squares;
    
        initStorage();
        bool stop = false;
        while (!stop)
        {
            cout << "----------------------------------" << endl;
            cap_1 >> frame_1;
            GaussianBlur(frame_1, frame_1, cv::Size(5, 5), 0, 0);//高斯滤波
            image_1 = &IplImage(frame_1);
            //image_1 = cvLoadImage("pic.png", 1);
            //image_1 = cvLoadImage("ggu.jpg", 1);
            //image_1 = cvLoadImage("ppo.png", 1);
    
            sz = cvSize(image_1->width, image_1->height);
            gray = cvCreateImage(sz, IPL_DEPTH_8U, 1);//创建头并分配数据
            cvCvtColor(image_1, gray, CV_BGR2GRAY);//灰度处理
            tc.setup(gray);//把灰度图传给tc
            tc.transform();
            cout << "v.size:" << tc.v.size() << endl;
    
            contour = cvCreateSeq(CV_SEQ_POLYGON, sizeof(CvSeq), sizeof(CvPoint), storage);//创建序列contour
            squares = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvPoint), storage);//创建序列squares
    
            double s, t;
            for(int i = 0; i < tc.v.size(); i++)
            {
                contour = transform(tc.v[i]);//返回轮廓
                result = cvApproxPoly(contour, sizeof(CvContour), storage, CV_POLY_APPROX_DP, cvContourPerimeter(contour)*0.02, 0);//逼近函数
                if (result->total == 4 && cvCheckContourConvexity(result))//检测是否是四边形和凸边形
                {
                    s = 0;
                    for (int j = 2; j < 5; j++)//for循环来判断四边形的顶点是否都是直角
                    {
                        t = fabs(angle(
                            (CvPoint*)cvGetSeqElem(result, j),
                            (CvPoint*)cvGetSeqElem(result, j - 2),
                            (CvPoint*)cvGetSeqElem(result, j - 1)));
                        s = s > t ? s : t;
                    }
                    if (s < 0.1)
                        for (int j = 0; j < 4; j++)
                            cvSeqPush(squares, (CvPoint*)cvGetSeqElem(result, j));//squares最后存储的就是矩形
                }
            }
    
            cout << "squares->total:" << squares->total/4 << endl << endl;
    
            CvSeqReader reader;
            cvStartReadSeq(squares, &reader, 0);
            int i;
            int x[4] = { 0 }, y[4] = { 0 };
            for (i = 0; i < squares->total; i += 4)//i+=4是因为四个点才是一矩形
            {
                CvPoint pt[4], *rect = pt;
                int count = 4;
                CV_READ_SEQ_ELEM(pt[0], reader);//for循环来读取顶点坐标
                CV_READ_SEQ_ELEM(pt[1], reader);
                CV_READ_SEQ_ELEM(pt[2], reader);
                CV_READ_SEQ_ELEM(pt[3], reader);
                cout << "--------square>>" << i/4+1 << endl;
                for (int i = 0; i<4; i++)
                {
                    x[i] = rect[i].x;
                    y[i] = rect[i].y;
                    cout << "x" << i << ":" << x[i] << '\t';
                    cout << "y" << i << ":" << y[i] << endl;
                }
                cvPolyLine(image_1, &rect, &count, 1, 1, CV_RGB(0, 255, 0), 1, CV_AA, 0);//在图像中用绿色线标出矩形区域
            }
            cvShowImage("Vedio_1", image_1);//显示窗口
            if (waitKey(27) >= 0)//Esc键退出
                stop = true;
        }
        releaseStorage();//释放内存
        return 0;
    }
    

    代码中有导师写的类所以需要先把导师的类转换成逼近函数需要的数据类型就花费了很长时间,不过这个过程让自己对opencv更了解了~~棒棒的 导师的最终任务是完成双目程序 不过这个代码里有3个问题!
    程序使用的样图
    这个是运行后的图片你可以看到绿色的框框就是程序识别的矩形
    这个是矩形坐标

    1.在图片中我们能看到所返回的矩形坐标是有偏差的暂时还没有解决~~
    2.检测矩形是会把外矩形也检测进去这个也仍未解决~~
    3.程序运行时所占用的内存会一直上升,上升到一定值时程序就会报错中止~~

    展开全文
  • 然后,根据检测到的边缘,从图像的矩形切口中得到卡片图像。但我不知道如何从精明的信息中获取边缘信息(坐标)。我可以获取精明的信息并将其存储到IplImage中,但我不确定如何获取在卡片周围创建矩形并剪切图像所需...

    我一直在想如何检测桌子上的卡片,然后提取卡片的图像。在阅读了一些资料之后,我认为最好使用cv.Canny进行边缘检测,因为卡片将是白桌子上唯一的东西。然后,根据检测到的边缘,从图像的矩形切口中得到卡片图像。

    但我不知道如何从精明的信息中获取边缘信息(坐标)。我可以获取精明的信息并将其存储到IplImage中,但我不确定如何获取在卡片周围创建矩形并剪切图像所需的信息。import cv

    cam = cv.CaptureFromCAM(0)

    while True:

    capture = cv.QueryFrame(cam)

    #apply mask to block out white background

    grey = cv.CreateImage(cv.GetSize(capture), 8, 1)

    masked_image = cv.CreateImage(cv.GetSize(capture), 8, 3)

    cv.CvtColor(capture, grey, cv.CV_BGR2GRAY)

    cv.Threshold(grey, grey, 100, 255, cv.CV_THRESH_BINARY)

    cv.Zero(masked_image)

    cv.Not(grey, grey)

    cv.Copy(capture, masked_image, grey)

    #detect corners

    corners = cv.CreateImage(cv.GetSize(masked_image), 8, 1)

    #cv.CornerHarris(masked_image, corners, ?)

    cv.Canny(grey, corners, 900, 890)

    cv.ShowImage('b_window', corners)

    cv.WaitKey(2)

    展开全文
  • 基于Opencv矩形区域简易检测方法

    千次阅读 2019-06-13 20:28:08
    2.使用opencv中的minAreaRect(contour)提取出轮廓的最小外切矩形。(如果蓝色区域存在内轮廓,可以将整个轮廓进行填充) 3.计算外切矩形区域中的蓝色像素所占的比例,如果接近于1(阈值可以规定),则可以认为是...
  • 主要为大家详细介绍了使用OpenCV检测图像中的矩形,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • opencv矩形检测

    万次阅读 2016-04-07 13:55:49
    // minangle,maxangle 检测矩形边夹角范围,单位为角度 //输出: 矩形序列 /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// CvSeq* findSquares4( IplImage* img, ...
  • OpenCV矩形检测及裁剪

    2019-04-24 20:01:58
    由于openCV 这个库单体文件大于100M ,传不上github。该demo没有导入openCV,导入了就可以使用了 (pod 'OpenCV','~> 2.4.13')最新的版本,由于有些接口改变太多,我这边导入的...2. 矩形的实时边缘检测及(视频流)
  • OpenCV 虚线矩形

    千次阅读 2016-02-25 17:38:25
    前两天查资料看opencv 画虚线矩形,先收录一下;后面有可能会用得到。不过代码没有测试。 OpenCV2.0提供了一些比较简单的绘图函数,比如绘制 矩形,椭圆,圆,多边形,直线;但都是实线,有时需要用做对比试验,虚线...
  • opencv矩形物体检测

    千次阅读 2013-04-30 18:44:34
    本文需要了解的库函数有: CvSeq* cvApproxPoly( const void* src_seq, int header_size, CvMemStorage* storage, int method, double parameter, int parameter2=0 ); //用指定的精度逼近多边形曲线 ...
  • OpenCV根据矩形轮廓进行倾斜校正。算法介绍可参考:http://blog.csdn.net/mengchicmc/article/details/77981112
  • opencv 查找矩形

    2012-07-22 13:08:10
    opencv 查找矩形 //矩形查找 BOOL CImageFun::FindSquares(IplImage *srcImage, double fMaxR, double fMinR, ARRCIR_XY_R &amp;ptarr, int npar1, int npar2) { CvSeq *contour; int header_size, i, ...
  • OpenCVopencv 检测直线、圆、矩形

    千次阅读 2016-03-30 14:59:49
    opencv 检测直线、圆、矩形 http://blog.csdn.net/byxdaz/article/details/4912136
  • 我如何解决从图像中识别和提取矩形的问题,如下图所示.请注意,我的矩形可能不完整,并且...之后,您可以使用page中的教程来检测简单的形状,例如矩形.我实现了一个快速演示,该演示适用于您提供的图像.main.py:import...
  • OpenCV 矩形轮廓检测

    万次阅读 2014-12-11 11:01:03
    #include "cv.h" #include #include #include #include #include ...#pragma comment(lib,"opencv_core2410d.lib") #pragma comment(lib,"opencv_highgui2410d.lib") #pragma comment(lib,"op
  • 矩形检测OPENCV

    2019-03-31 22:00:30
    矩形检测,采用OPENCV开发,通过轮廓获得矩形,效果比较好
  • 矩形检测opencv代码

    2019-02-26 14:47:02
    矩形检测opencv代码,压缩包中有测试用图,代码可以直接调用使用。
  • opencv矩形

    千次阅读 2019-02-12 11:50:02
    Rectangle 画矩形 C++: Mat类 void rectangle(Mat&amp; img,Point pt1, Point pt2, const Scalar&amp;color,  int thickness=1,int lineType=8, int shift=0) void rectangle(Mat&amp; img,cvPoint(x, ...
  • opencv 检测直线、圆、矩形

    万次阅读 2009-12-01 09:26:00
    检测直线:cvHoughLines,cvHoughLines2检测圆:cvHoughCircles检测矩形opencv中没有对应的函数,下面有段代码可以检测矩形,是通过先找直线,然后找到直线平行与垂直的四根线。 检测直线代码:/* This is a ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 13,723
精华内容 5,489
关键字:

opencv检测矩形