Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:36:54+00:00 2026-06-17T04:36:54+00:00

Hi I am working on computer vision project and trying to detect square by

  • 0

Hi I am working on computer vision project and trying to detect square by using openCV/C++ from camera. I had download the source code from openCV library but it seems like losing fps so hard. Does anybody have idea how to fix this problem? There is a video link about my testing below, check it out:
http://magicbookproject.blogspot.co.uk/2012/12/detect-paper-demo.html

Here is the code and just found on another post:

void find_squares(Mat& image, vector<vector<Point> >& squares)
{
// blur will enhance edge detection
Mat blurred(image);
medianBlur(image, blurred, 9);

Mat gray0(blurred.size(), CV_8U), gray;
vector<vector<Point> > contours;

// find squares in every color plane of the image
for (int c = 0; c < 3; c++)
{
    int ch[] = {c, 0};
    mixChannels(&blurred, 1, &gray0, 1, ch, 1);

    // try several threshold levels
    const int threshold_level = 2;
    for (int l = 0; l < threshold_level; l++)
    {
        // Use Canny instead of zero threshold level!
        // Canny helps to catch squares with gradient shading
        if (l == 0)
        {
            Canny(gray0, gray, 10, 20, 3); // 

            // Dilate helps to remove potential holes between edge segments
            dilate(gray, gray, Mat(), Point(-1,-1));
        }
        else
        {
                gray = gray0 >= (l+1) * 255 / threshold_level;
        }

        // Find contours and store them in a list
        findContours(gray, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);

        // Test contours
        vector<Point> approx;
        for (size_t i = 0; i < contours.size(); i++)
        {
                // approximate contour with accuracy proportional
                // to the contour perimeter
                approxPolyDP(Mat(contours[i]), approx, arcLength(Mat(contours[i]), true)*0.02, true);

                // Note: absolute value of an area is used because
                // area may be positive or negative - in accordance with the
                // contour orientation
                if (approx.size() == 4 &&
                        fabs(contourArea(Mat(approx))) > 1000 &&
                        isContourConvex(Mat(approx)))
                {
                        double maxCosine = 0;

                        for (int j = 2; j < 5; j++)
                        {
                                double cosine = fabs(angle(approx[j%4], approx[j-2], approx[j-1]));
                                maxCosine = MAX(maxCosine, cosine);
                        }

                        if (maxCosine < 0.3)
                                squares.push_back(approx);
                }
        }
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:36:55+00:00Added an answer on June 17, 2026 at 4:36 am

    You can speed it up if you don’t mind losing accuracy. For example

    // find squares in every color plane of the image
    for (int c = 0; c < 3; c++)
    

    You are looping through three color planes. Just examine one color (as if the image is grayscale), that should triple the speed.

    Also try without Canny, which is quite slow. Set a use_canny parameter,

     if (l == 0 && use_canny)
         {
            Canny(gray0, gray, 10, 20, 3); // 
    

    Compare with and without. I am getting acceptable results, considerably faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Computer Vision system with OpenCV in C++. I wrote a
New to Android and OpenCV. Been trying to to implement code from new book,
I'm working on a computer vision problem which requires rendering a 3d model using
Where can I find working code of object detection (part of computer vision) written
I'm working on a Computer Science project, and I haven't been able to find
Good afternoon, WinUSB is working well on the development computer that I am using
I'm working with a set of images and computer vision. I want to compare
I am trying to practice good de-coupled architecture in my computer vision app. Since
I have been working on a project which is about data copy from one
I am working on a C++ application that uses computer vision techniques to identify

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.