Ask Your Question

Tharaki's profile - activity

2015-09-28 10:13:16 -0500 received badge  Notable Question (source)
2015-05-04 19:41:13 -0500 received badge  Notable Question (source)
2014-07-31 05:09:04 -0500 received badge  Popular Question (source)
2014-02-05 09:06:05 -0500 received badge  Nice Question (source)
2013-12-03 14:59:48 -0500 received badge  Popular Question (source)
2012-08-11 03:53:15 -0500 asked a question Detect square using opencv2.4

i used a program to detect square in an image. that is working well with the image that i download from the internet. but what should i do is detect squares of the image which is taken from a camera. first of all i extracted images from video and then i try to detect square from those set of images but the code is not working for those extracted images(but that is working well with other images ). what should i do to complete that task?

#ifdef _CH_
#pragma package <opencv>
#endif

#define CV_NO_BACKWARD_COMPATIBILITY

#include <opencv2/opencv.hpp> 
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <math.h>
#include <string.h>

int thresh = 50;
IplImage* img = 0;
IplImage* img0 = 0;
CvMemStorage* storage = 0;
//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 ...
(more)
2012-08-10 15:40:38 -0500 received badge  Scholar (source)
2012-08-10 15:40:30 -0500 commented question How to detect square in a video using c++ and opencv?

Thank you very much.now on words i'm going to study about both Chamfer Matching and Line2D. i think i could find solution from them.

2012-08-10 14:58:32 -0500 commented question How to detect square in a video using c++ and opencv?

thank you very much for helping. i attached an example to this question.

2012-08-10 14:56:16 -0500 received badge  Editor (source)
2012-08-10 14:18:42 -0500 received badge  Student (source)
2012-08-10 13:43:13 -0500 asked a question How to detect square in a video using c++ and opencv?

I want to build an program that can detect square shape object in a video. i used SURF algorithm for that. but that only detect key points.i want to detect square shape objects which are situated near the road. As a example road signs. the program simply check whether the frame that taken by camera (which is putting inside the vehicle) has square sign or not.(if that frame has square shape object then frame is sent to next function, else delete that)