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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:55:35+00:00 2026-06-07T08:55:35+00:00

I have this project where I need (on iOS) to detect simple geometric shapes

  • 0

I have this project where I need (on iOS) to detect simple geometric shapes inside an image.

enter image description here

After searching the internet I have concluded that the best tool for this is OpenCV. The thing is that up until two hours ago I had no idea what OpenCV is and I have never even remotely did anything involving image processing. My main experience is JS/HTML,C#,SQL,Objective-C…

Where do I start with this?

I have found this answer that I was able to digest and by reading already other stuff, I understand that OpenCV should return an Array of shapes with the points/corners, is this true? Also how will it represent a circle or a half circle?
Also what about the shape orientation?

Do you know of any Demo iOS project that can demonstrate a similar functionality?

  • 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-07T08:55:36+00:00Added an answer on June 7, 2026 at 8:55 am

    If you have only these regular shapes, there is a simple procedure as follows :

    1. Find Contours in the image (image should be binary as given in your question)
    2. Approximate each contour using approxPolyDP function.
    3. Check number of elements in the approximated contours of all shapes to recognize shape. For eg, square will have 4, pentagon will have 5. Circles will have more, I don’t know, so we find it. (I got 16 for circle and 9 for half-circle)
    4. Now assign the color, run the code for your test image, check its number, fill it with corresponding colors.

    Below is my example in Python:

    import numpy as np
    import cv2
    
    img = cv2.imread('shapes.png')
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    
    ret,thresh = cv2.threshold(gray,127,255,1)
    
    contours,h = cv2.findContours(thresh,1,2)
    
    for cnt in contours:
        approx = cv2.approxPolyDP(cnt,0.01*cv2.arcLength(cnt,True),True)
        print len(approx)
        if len(approx)==5:
            print "pentagon"
            cv2.drawContours(img,[cnt],0,255,-1)
        elif len(approx)==3:
            print "triangle"
            cv2.drawContours(img,[cnt],0,(0,255,0),-1)
        elif len(approx)==4:
            print "square"
            cv2.drawContours(img,[cnt],0,(0,0,255),-1)
        elif len(approx) == 9:
            print "half-circle"
            cv2.drawContours(img,[cnt],0,(255,255,0),-1)
        elif len(approx) > 15:
            print "circle"
            cv2.drawContours(img,[cnt],0,(0,255,255),-1)
    
    cv2.imshow('img',img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

    Below is the output:

    enter image description here

    Remember, it works only for regular shapes.

    Alternatively to find circles, you can use houghcircles. You can find a tutorial here.

    Regarding iOS, OpenCV devs are developing some iOS samples this summer, So visit their site: http://www.code.opencv.org and contact them.

    You can find slides of their tutorial here

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

Sidebar

Related Questions

I have found this project on Codeplex. http://www.codeplex.com/ProjNET I need to integrate this code
I have this simple test project just to test the IncludeExceptionDetailInFaults behavior. public class
I need a calendar View in my iOS 5 project. I found this Library
I have this Project model: class Project < ActiveRecord::Base validates :status, :inclusion => {
I have this project that it's due in a few hours and I still
So I have this project in PHP where I have some include files next
Okay so, I have this project structure: package A.B class SuperClass (this class is
I have this WinForms project (based on this one , but modified for SharePoint
I have been handed this project that has a large number of issues with
I have this task for the project with 4 nested subprojects using Maven: For

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.