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 8913219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:24:13+00:00 2026-06-15T04:24:13+00:00

I have this image : And i want take out the triangle and rectangles

  • 0

I have this image:

And i want take out the triangle and rectangles from the image. I have 2 algorithmes, one for triangles and another for rectangles in the code below. But they are very similar. But in this way i only can take out the triangle more bright. Can anyone help me please.

IplImage* DetectAndDrawTriang(IplImage* img){
    CvSeq* contours;
    CvSeq* result;
    CvMemStorage *storage = cvCreateMemStorage(0);
    int d=30;

    IplImage* ret = cvCreateImage(cvGetSize(img), 8, 3);
    IplImage* temp = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
    cvSet(ret,cvScalar(0,0,0));
    cvCvtColor(img, temp, CV_BGR2GRAY);
    cvThreshold( temp, temp, 180, 255, CV_THRESH_BINARY );
    //cvSmooth(temp, temp, CV_GAUSSIAN, 9, 9, 0,0);
    cvNamedWindow("thre");
    cvShowImage("thre", temp);

    cvFindContours(temp, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));

    while(contours)
    {
        result = cvApproxPoly(contours, sizeof(CvContour), storage, CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.1, 0);
        if(result->total==3)
        {
            CvPoint *pt[3];
            for(int i=0;i<3;i++)
                pt[i] = (CvPoint*)cvGetSeqElem(result, i);


            if((int)sqrt((pt[0]->x-pt[2]->x)*(pt[0]->x-pt[2]->x)+(pt[0]->y-pt[2]->y)*(pt[0]->y-pt[2]->y))>=d && (int)sqrt((pt[0]->x-pt[1]->x)*(pt[0]->x-pt[1]->x)+(pt[0]->y-pt[1]->y)*(pt[0]->y-pt[1]->y))>=d && (int)sqrt((pt[1]->x-pt[2]->x)*(pt[1]->x-pt[2]->x)+(pt[1]->y-pt[2]->y)*(pt[1]->y-pt[2]->y))>=d)
            {
                cvLine(ret, *pt[0], *pt[1], cvScalar(255,255,255));

                cvLine(ret, *pt[1], *pt[2], cvScalar(255,255,255));

                cvLine(ret, *pt[2], *pt[0], cvScalar(255,255,255));
            }
        }
        contours = contours->h_next;
    }

    cvReleaseImage(&temp);
    cvReleaseMemStorage(&storage);

    return ret;

}
  • 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-15T04:24:15+00:00Added an answer on June 15, 2026 at 4:24 am

    One Idea I can think of is using the cv::matchShapes function (I suggest using the cv2 library with Mat instead of Ipl images). matchShapes takes a Mat of the object you want to detect and a Mat of the object you want to compare it against. So in your case you can make a Mat of the contours of a triangle and square and compare those images with each contour in the image your are searching through.

    You may also consider simply doing template matching since your objects are static. Check out cv::matchTemplate and its pretty much the same idea as the above paragraph.

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

Sidebar

Related Questions

I want to draw image in place where I click. i have this code:
I want to force the download of an image. I have found this code:
I have this image: What I want to do is to add a UITapGestureRecognizer
I have a UIProgressView which I want to look like this image. I have
So I have Image like this (source: de-viz.ru ) I want to get something
So I have Image like this (source: de-viz.ru ) I want to get something
I have the image like this: I want to split it into six squares,
I have a bitmap image context and want to let this appear blurry. So
I want to do this: I have a div with item: title, image, some
i have many div's with the same background image and i want change this

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.