Contours & Masks using Python & OpenCV - How to separate object from image background?

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 พ.ย. 2024

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

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

    Control mouse with fly swatter!
    th-cam.com/video/VcnqoXxiz00/w-d-xo.html
    00:00 Intro
    00:56 Coding starts here...
    01:10 Loading original image
    04:18 Converting image to gray scale
    05:06 Converting image to black and white
    09:40 Extracting all contours
    11:43 Extracting most significant contours
    14:13 Traversing contours in various ways
    18:29 Masking background
    25:09 Placing object onto a new background
    25:35 END RESULT & SUMMARY

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

    Great video, chapter titles and intro all spot on man!!

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

      Thanks man) Now I'm trying to do the same but with the video stream frames sourced from my webcam... it's more complicated and needs to take into a count some additional details.

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

    Trully excellent...the only working solution
    One big question ...suppose the image had a little more info.... like 2 little birds flying near the face (NOT on the face) ...how could I have them removed ?

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

      Contours are being detected and enumerated in this method so you just need to pick up relevant and drop those you don't need, I mean like birds near the face should also be detected just like the face ones but less significant in terms of weight/order, so I believe after a bit of tinkering it should finally work.

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

    Great video, thanks!

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

    Very useful. Thanks a bunch.

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

      You're welcome)

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

      @@monkey_see_monkey_do Hi. I am able to convert image background to red,green or blue color but facing issue when I am trying to add white in the background. If I use (255,255,255) in the fill polygon and later perform the and operation, background does not change to white color, instead it gives the original image. Can you please help me with this.

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

      @@heenagirdher6443 If clearly got what you've meant then the reason of such behavior is following: 255 in decimal is 0xFF in hex and 1111 1111 in binary so if you bitwise AND with the original image it would remain the same. However I'm not claiming that this is the case because I don't know how fill polygon works internally. A possible workaround might be the following:
      1. Fill polygon with say green
      2. Create a new mask and overlay the copy of this painted green shape onto it, then replace the background with white and the green with white manually
      3. Use the mask to distinguish the pixels on the original image and turn them to 255 manually in a loop.
      This might not be the best ever idea if you need to it fast, for instance in a video.

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

      @@monkey_see_monkey_do This approach isn't working. If I fill polygon with green and after that when I perform bitwise operation, value of every pixel color got change. As the color is dark so it is not recognized but after checking I come to know that value of pixels got changed.

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

      @@heenagirdher6443 and what if swap the values in mask?

  • @BilalKhan-fn5mr
    @BilalKhan-fn5mr 11 หลายเดือนก่อน +1

    Love it

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

    🤘

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

    Great tutorial! I have a question though.. how would I be able to segment an image from the background? Like if there was an object and behind it a blue background. How would I be able to just get the object without the blue background?

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

      since this method is based on finding contours background color doesn't matter.

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

      There is a video here in TH-cam in which someone explains how to remove the background, although I think it is not necessary

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

      Any ideas about counting the number of times the same countur appears in the image?

  • @jacksonwang-iris
    @jacksonwang-iris 2 ปีที่แล้ว

    How about getting binary image by canny instead of threshold and using a complicated picture! you may find it will be difficult to deal with.

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

    Identify the eyes nose mouth hair in a black & white image and give it a color

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

      Face elements recognition makes sense on real photos. Here the black and white image serves the only purpose of having a small amount of contours to work with.

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

    Hi great tutorial.
    I have one query, in my image what I have, I'm not getting the mask at the background. It is happening on the object. So could u plz provide me ur email id or Linkdin so that I can able to tackle this issue...?