OpenCV Python Tutorial For Beginners 25 - Detect Simple Geometric Shapes using OpenCV in Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ม.ค. 2025

ความคิดเห็น • 71

  • @TheNightFox919
    @TheNightFox919 4 ปีที่แล้ว +15

    For anyone wondering: the parameter epsilon in the method approxPolyDP represents the maximum distance between the shape and the approximation. If epsilon = 0 then the approximation will be really precise. But the bigger epsilon gets, the further you allow your approximation to be less rigorous, and an epsilon that's too big will simply not detect shapes properly.
    Trying the code as it is in the video on some random shapes image I found on google, I get that 0.01*cv2.arcLength(contour, closed=True) is actually an approximation that's "too good" (as in it'll try and draw more than 3 edges on a triangle). I put epsilon = 3 and it seems to do the job fine. Depending on what you're coding and how precisely you want to detect, play around with the epsilon value.

  • @BipinJethwani
    @BipinJethwani 2 ปีที่แล้ว

    You're awesome. Your Github Gist works

  • @Its-Not-Funny
    @Its-Not-Funny 4 ปีที่แล้ว +3

    We can also use
    width == height instead of using aspect ratio, it will work as same as the ratio and it is simple to understand. (If w == h: "square")

    • @theearthish
      @theearthish 4 ปีที่แล้ว +1

      I think aspect ratio is used so that it takes care of any error in the boundingRect method

    • @haastrupadebayoibukun6817
      @haastrupadebayoibukun6817 2 ปีที่แล้ว

      @@theearthish The aspect ratio was used because of the noise. Under normal situation, the width and height of a square is the same, in that situation the aspect ratio will be 1.

  • @LaurinusPonpon
    @LaurinusPonpon 5 ปีที่แล้ว +1

    Can't wait the next one!

  • @jun2705
    @jun2705 4 ปีที่แล้ว

    Thanks for this great video!

  • @chapaalejandro90
    @chapaalejandro90 5 ปีที่แล้ว +7

    where do I find the shapes.jpg file? I could not find it in OpenCV github

    • @JJVR10
      @JJVR10 5 ปีที่แล้ว +5

      I did it using paint. It took me 2 min. All the shapes are there.

  • @saifaldeenal7451
    @saifaldeenal7451 5 ปีที่แล้ว

    Thanks a lot, wonderful!

  • @TrungNguyen-tm6fd
    @TrungNguyen-tm6fd 4 ปีที่แล้ว

    great. Thank you for this video.It helped me a lot.

  • @fun-ih5sc
    @fun-ih5sc 4 ปีที่แล้ว +7

    Can anybody tell me why it is multiplied with "0.01" at 5:40 ,Line no: 10.
    I was liking his way of explaining things but totally disappointed now.
    Not explaining basic only -_- 👎

    • @shubhambagdare6600
      @shubhambagdare6600 4 ปีที่แล้ว

      Did u listen to the whole thing? The closer your epsilon value is to 0, the more precise is your approximation of the curve and so your shape will be detected more precisely. Learn to listen.

    • @adityaanand5686
      @adityaanand5686 4 ปีที่แล้ว

      @@shubhambagdare6600
      Did u listen to the whole thing?
      Where it is mentioned "The closer your epsilon value is to 0, the more precise is your approximation"??
      Btw thanks for clearing my doubt.

    • @rishabhkumar8415
      @rishabhkumar8415 3 ปีที่แล้ว

      @@adityaanand5686 You are fool someone is helping you and you are giving reply to him in negative way instead of Say Thanks

  • @danielmeireles1
    @danielmeireles1 3 ปีที่แล้ว

    Thanks for sharing!

  • @lewlew212
    @lewlew212 ปีที่แล้ว

    If with the above problem, I want to identify parallelogram, what should I do? Looking forward to your support. Thank!

  • @Ironslayer423
    @Ironslayer423 5 หลายเดือนก่อน

    How can we detect something which is combination of two or more geometries, like an arrow?

  • @RahulKumar-tl4dv
    @RahulKumar-tl4dv 5 ปีที่แล้ว

    Thanks for video

  • @JalalKhan-we1th
    @JalalKhan-we1th 3 ปีที่แล้ว

    Will this python program work in real time geometric shapes detection.??

  • @parthasaha4174
    @parthasaha4174 3 ปีที่แล้ว

    Can you help me with the "trackbar" to find the threshold values?

  • @saipatil2462
    @saipatil2462 3 ปีที่แล้ว

    Hello. Can you please tell how can we detect the same in live video.

  • @shivakumark4275
    @shivakumark4275 3 ปีที่แล้ว +1

    I'm getting error in line 5 .. Should I need to save the 'shapes.jpg' to a specific path?

    • @reealtech_xr
      @reealtech_xr 3 ปีที่แล้ว +1

      you need to enter the full path with image name and extension. Example: "E:/saurabh/image/shape.jpg"

    • @shivakumark4275
      @shivakumark4275 3 ปีที่แล้ว +1

      @@reealtech_xr thanks bro ❤

  • @memonaijaz5429
    @memonaijaz5429 5 ปีที่แล้ว +1

    How to get there x,y coordinates values

  • @xueyuanye
    @xueyuanye 2 ปีที่แล้ว

    where could I download the shapes.jpg for testing? Thanks a lot

  • @gurakashsidhu8256
    @gurakashsidhu8256 3 ปีที่แล้ว

    Hi guys I was just wondering if I could use this code for nuts shape classification and detection?
    any help is appreciated.

  • @pedramtehranchi9653
    @pedramtehranchi9653 5 ปีที่แล้ว

    Thanks a lot

  • @shashanksharmadon4295
    @shashanksharmadon4295 5 ปีที่แล้ว

    thanks bro......

  • @abdeldjalilettaharboucetta2238
    @abdeldjalilettaharboucetta2238 4 ปีที่แล้ว

    hi thanks for the tutorial
    can you tell us how we can do it in real time ? not just for an image ,and thank you

  • @surajveertalreja9438
    @surajveertalreja9438 4 ปีที่แล้ว

    what if the object is a vehicle or plant? we can definitely identify them but how can we name it? like we used 3 sides for triangle and so on. What can be the logic to name car and say cactus?

    • @kumarabhishek5652
      @kumarabhishek5652 4 ปีที่แล้ว

      maybe car would fall in the category of trapezoid.

    • @theearthish
      @theearthish 4 ปีที่แล้ว

      That falls under object recognition

  • @henokadisumebratu7268
    @henokadisumebratu7268 4 ปีที่แล้ว

    do you have a live version of this which can detect from webcam , please

    • @heyawaltuh
      @heyawaltuh 3 ปีที่แล้ว

      cap = cv2.VideoCapture(0)

  • @rio2414
    @rio2414 5 ปีที่แล้ว

    can i use this for movement shapes

  • @பி.அம்ரித
    @பி.அம்ரித 5 ปีที่แล้ว

    sir what is the aspect ratio for rectangle because i want do for trapozoids also...!

    • @venur8153
      @venur8153 4 ปีที่แล้ว

      Can u know aspect ratio of rhombus?

  • @InfoPOLRES
    @InfoPOLRES 3 ปีที่แล้ว

    You saved me woahhhhh from pepe's fury

  • @memonaijaz5429
    @memonaijaz5429 5 ปีที่แล้ว +1

    How can i get there x,y coordinates values?

    • @SigmaLiving
      @SigmaLiving 4 ปีที่แล้ว

      Did you ever solve this?

    • @ndsingh2368
      @ndsingh2368 4 ปีที่แล้ว

      any luck in getting shapes x, y coordinates?

  • @btigenie
    @btigenie 4 ปีที่แล้ว

    No matter what I try, I get the error - "too many values to unpack (expected 2)" on the countours definition line. I am running directly from the repo and with the downloaded image file noted in comments.

    • @abdeldjalilettaharboucetta2238
      @abdeldjalilettaharboucetta2238 4 ปีที่แล้ว

      i think you run it in python 2 not 3 or you didnt upgrade the version of opencv

    • @Its-Not-Funny
      @Its-Not-Funny 4 ปีที่แล้ว

      It is because , the findContours will give 2 outputs. May be you are giving like (contours = cv2.findcontours(" ") ). You have to give like( contours, _ = cv2. ........).

    • @beatrizaubele369
      @beatrizaubele369 3 ปีที่แล้ว

      Try with "_, contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)"
      Too late but it can probably help someone in the future.

  • @sethwhite4155
    @sethwhite4155 4 ปีที่แล้ว

    I can't find the shapes image. Help?

  • @puturoi
    @puturoi 4 ปีที่แล้ว +2

    неужели нельзя приложить файл с этой е.бучей картинкой?

  • @dandavatisuhas5428
    @dandavatisuhas5428 4 ปีที่แล้ว

    how to detect the color of a simple shape in opencv ? could you please give me any references?

    • @mihirsrivastava2460
      @mihirsrivastava2460 4 ปีที่แล้ว

      You here for eyrc?

    • @hardikkamboj3528
      @hardikkamboj3528 3 ปีที่แล้ว

      @Dandavati You can change the image to HSV, and then use value of Hue to detect the color.

  • @nikhilrizal3729
    @nikhilrizal3729 4 ปีที่แล้ว

    What does ravel does

    • @Its-Not-Funny
      @Its-Not-Funny 4 ปีที่แล้ว

      As per my knowledge , ravel will give the starting point of contour draw in img pixel. So x will give x- coordinate
      Y- gives y coordinate.

    • @kamathprajna
      @kamathprajna 3 ปีที่แล้ว

      @@Its-Not-Funny do this code works

  • @venur8153
    @venur8153 4 ปีที่แล้ว

    How to find colour of the shapes? Can anyone help

    • @RiteshNEVERUNIFORM
      @RiteshNEVERUNIFORM 4 ปีที่แล้ว +1

      Are you from Nirikshuk bot ?

    • @venur8153
      @venur8153 4 ปีที่แล้ว

      @@RiteshNEVERUNIFORM yeah

    • @venur8153
      @venur8153 4 ปีที่แล้ว

      @@RiteshNEVERUNIFORM I sort out this one but I am struggling in task _b

    • @pranitham1586
      @pranitham1586 4 ปีที่แล้ว

      Did this code help u to solve nirishuk task 1

  • @karishmatyagi3585
    @karishmatyagi3585 4 ปีที่แล้ว +3

    Instead of displaying the shape name once, it shows multiple times. Anyone faced the same issue?

    • @HK-ct1tg
      @HK-ct1tg 4 ปีที่แล้ว

      I faced the same issue. Did you find a solution for it ?

    • @rishi2405
      @rishi2405 4 ปีที่แล้ว

      I had that too, the reason for mine was i didn't use elif for the other if statements after the first one

    • @gauninha12
      @gauninha12 4 ปีที่แล้ว

      Im also facing this problema, and im using elif statements though

    • @kamathprajna
      @kamathprajna 3 ปีที่แล้ว

      @@gauninha12 help??how?

    • @sushrutkenkre105
      @sushrutkenkre105 ปีที่แล้ว +2

      Reduce the threshold. It is working perfectly after reducing. I changed mine from 240 to 225.

  • @NiteshGupta-jr6ib
    @NiteshGupta-jr6ib 5 ปีที่แล้ว

    there are way too many ads in between.

  • @austinyan1616
    @austinyan1616 4 ปีที่แล้ว

    You're only reading through the code. Total waste of time.

    • @HM-cw8im
      @HM-cw8im 4 ปีที่แล้ว

      Have you watched the previous videos? Most of the functions are explained there.