Detecting color with Python and OpenCV using HSV colorspace | Computer vision tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ก.พ. 2025
  • Code: github.com/com...
    #computervision #opencv #colordetection

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

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

    Did you enjoy this video? Try my premium courses! 😃🙌😊
    ● Hands-On Computer Vision in the Cloud: Building an AWS-based Real Time Number Plate Recognition System bit.ly/3RXrE1Y
    ● End-To-End Computer Vision: Build and Deploy a Video Summarization API bit.ly/3tyQX0M
    ● Computer Vision on Edge: Real Time Number Plate Recognition on an Edge Device bit.ly/4dYodA7
    ● Machine Learning Entrepreneur: How to start your entrepreneurial journey as a freelancer and content creator bit.ly/4bFLeaC
    Learn to create AI-based prototypes in the Computer Vision School! www.computervision.school 😃🚀🎓

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

      I'm your big fan ,following since you have started channel. Now I'm unable to deploy my project live on github . Can you help me to live the project.

  • @vidyashree7652
    @vidyashree7652 2 หลายเดือนก่อน +3

    This video has just been the 1st and the best video I have landed for my CV project. Thank you for this video!

    • @ComputerVisionEngineer
      @ComputerVisionEngineer  2 หลายเดือนก่อน

      Glad you enjoyed it! I hope it helps with your project! 😃🙌

  • @Lux1431996
    @Lux1431996 11 หลายเดือนก่อน +4

    This is so perfectly what I was looking for. Thank you so much! Might enable me to build a great production inline measurement system for "a penny".

  • @anushkanarsima9048
    @anushkanarsima9048 6 วันที่ผ่านมา

    my favourite channel for CV projects, tysm as always!

  • @nasirsaeed1168
    @nasirsaeed1168 22 วันที่ผ่านมา

    Love this. Best course to get started.

  • @kiitanayandosu-ug7pe
    @kiitanayandosu-ug7pe 10 หลายเดือนก่อน +1

    This was such an amazing tutorila thank you so much!

  • @nagireddygajjela5430
    @nagireddygajjela5430 4 หลายเดือนก่อน

    Great video. Thank you for sharing your knowledge on computer vision

  • @drushtiladhani8370
    @drushtiladhani8370 ปีที่แล้ว +6

    hey
    i am getting error in this line
    hsvImage = cv2.cvtColor(imageFrame, cv2.COLOR_BGR2HSV)
    please tell me how to solve
    cv2.cvtColor- in this

  • @geppetox748
    @geppetox748 3 หลายเดือนก่อน

    Excellent Sir, thank you! :)

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

    Amazing channel, god bless you❤

  • @isagive
    @isagive 17 วันที่ผ่านมา

    תודה רבה 💪👏

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

    this is better than pysource tutorial. how is it that all spanish guys are experts in CV? :)

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

    Cool explanation, thank you sir

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

    Very useful tutorial, thanks.

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

    so cool.thank you, learned a lot!

  • @herojesse
    @herojesse 6 วันที่ผ่านมา

    Do you still reply to comments if so what is the program you are using to code? do you know if its available on raspberry PI 4? I'm new to all this so sorry if im being dumb and its common knowlage

  • @RishiKumar-vb7fy
    @RishiKumar-vb7fy ปีที่แล้ว +1

    Can we make something where camera detects the colour in traffic light and tells what colour is the light and it will assist the colourblind people if they are confused. Blinking yellow and blinking red is tough for them. It may be a good project.

  • @selamushirtawi3909
    @selamushirtawi3909 11 หลายเดือนก่อน +2

    i am facing the following error
    cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

    • @andrecastro5878
      @andrecastro5878 3 หลายเดือนก่อน

      make sure you have selected the correct camera, if you only have one camera on your device then the correct line would be:
      cap = cv2.VideoCapture(0)

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

    Thank you! It is so concise! May I know could this be further refined to detect objects based on the criteria like shape (eg rectangle in different orientation) and size (eg pixel x pixel)? Thanks!

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

      Yes, it can be done. You can further refine it to detect objects of a given color based on size and approx orientation. 🙌

  • @dwaipayansarkar1815
    @dwaipayansarkar1815 10 หลายเดือนก่อน +3

    Your code is not properly working tho

  • @nikolaiownz
    @nikolaiownz 9 หลายเดือนก่อน

    Can you do a tutorial on how to regognise light a few colors light and the maybe log in into a excel for data to use. i want to make a uptime logger for my cnc machines

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

    How have you chosen a upper and lower limit? You have used some formula and I couldn't understand it?

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

      The 'color' is given by the hue channel, so from the h value for yellow, I set the interval as +- 10.

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

    Is there a way to display an array at the center of the webcam and if a certain color gets in that array it will send some sort of signal to a mechanism?

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

    I'm thinking of a device in the form of a video camera. This device will consist of a RaspberryPi, a camera module and display. This device will demonstrate the operation of the program for participation in roboracing. I propose to create a team to work on this project. In the future, it will be possible to participate in the OpenCV AI Competition 2023+n with this project. From Uruguay, you can participate in the competition)

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

      Sounds great! I think I won't be able to join, but best of luck with your project! 😃🙌

  • @נדבעמאר
    @נדבעמאר ปีที่แล้ว

    Very useful tutorial, thank you!
    i would like to know how to make it work on black?

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

      Have you tried by changing the bgr color to black (0, 0, 0)? Let me know if it works! 🙌

  • @dwaipayansarkar1815
    @dwaipayansarkar1815 10 หลายเดือนก่อน

    In the get limits function
    c = np.uint8([[yellow]])
    is throwing error

  • @drm8164
    @drm8164 7 หลายเดือนก่อน

    Excuse me Sir, please can I ask you a question: I just decided to pay for the OpenCV certification, its 1500 canadian dollars, and I m pretty convinced that it is a great investment for my future career in CV.
    Please can you give me your opinion? It will be a great help
    Thank you in advance :)

  • @waseemahmed4487
    @waseemahmed4487 3 หลายเดือนก่อน

    sir can u plz tell me where your running your code

  • @perth-ambhattarai4106
    @perth-ambhattarai4106 ปีที่แล้ว

    Thannnk You!!!!!! That was smoooooooooothhhhhhhhhhh

  • @Tintareza
    @Tintareza 4 หลายเดือนก่อน

    sir, Does this affect the camera lighting?

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

    How can I use my elgato capture card as the capture, I've tried looking everywhere?

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

    Hi how can i connect the system to the alarm system specifically a buzzer while using a laptop camera for the video capturing, hope you will assist me

  • @Ash2Tutorial
    @Ash2Tutorial 3 หลายเดือนก่อน

    The video is good, but I am not able to find the code for this tutorial. Could you provide the code link. Thanks

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

    hello can you help me, i have some problem in here. i got message ModuleNotFoundError: No module named 'PIL'. how i can fix it?

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

      You may need to install Pillow. 'pip install Pillow' should do the work 💪💪

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

    Hi , is that possible to add multiple boundary /square frame thingy to detect multiple object ?

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

      Hey, yes it is possible, you could try by getting the bounding boxes of all connected components, the same way I did in the parking spot detector and counter video. 💪🙌

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

    Hello, I'm trying to create a program that detects and counts objects by color, but now I can only count four colors, these are red, blue, green and yellow. I wonder if I can add the whole color scale to the program, how can I do this? I will be very happy if you give back. have a nice day😊

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

      Hey, I think adding the entire color scale to the program will be very challenging. I would suggest to add more colors incrementally until performance is affected. 🙌

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

    Even small pixels of yellow are detected, from the background, how do I increase the priority to be for just the object

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

      You could apply a blur to remove the small yellow pixels before applying the color detection.

    • @Harbin_07
      @Harbin_07 5 วันที่ผ่านมา

      @@ComputerVisionEngineer I am trying, but I cannot find a way. Can you make a small guide on it? I have been trying.

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

    i have a a problem sir when i try to detect a red color for example [0,0,255] it does not work ? i hope u reply and thanks

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

      Hey, maybe you need to try with different forms of red, as specified here www.rapidtables.com/web/color/red-color.html. Have you tried other colors?

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

    amazing video !

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

    like it, really cool video.. the kicker for me was the "BRG" .. it really confused me for a while.. was experimenting with the values there.. was trying to read the color of a led which i thought was green but was more white:ish with a green halo haha, is it possible to detect more colors at the same time ?

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

      Yeah, I hear you, something is tricky to specify the exact hue of a given color. About detecting more than one color at the same time: yes, absolutely! The code can be adapted to detect as many colors as you wish! 😃💪

  • @ibrahim.basaran
    @ibrahim.basaran 11 หลายเดือนก่อน

    i want to set up color for red. how ca i do it. i need little help

    • @wexxc
      @wexxc 11 หลายเดือนก่อน

      Just set the color to red lol
      Just look up on the internet what's the BGR Colorspace of red

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

    Great video but I have a slight issue it says TypeError: VideoCapture() takes no arguments. I'm assuming this means its having trouble finding my webcam footage but I'm not sure how to fix it

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

      also the 2 in VideoCapture(2) shows up as an unexpected argument

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

      what opencv version are you using? what is your Python version and your OS? are you using an IDE?

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

      @@ComputerVisionEngineer im using Pycharm vers 3.11 on a windows. not sure what version of opencv it is i think its 22.3.1 if that sounds right.

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

      sorry no 4.6.0

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

      Please try to execute it without pycharm, also try with other Python version and other version of opencv.

  • @nezarsharif
    @nezarsharif 3 วันที่ผ่านมา

    you are superman

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

    instead of that i want the code to analyse the colour of my face, can you please guide??

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

    when I tried red instead of yellow it didn't detect it even if I try different forms of red. I would really appreciate it if you help me

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

      Hey, I took a look and there was a bug which affected the performance in the case of red hues, thank you for noticing it. It is fixed now, take a look at the repo. 💪🙌

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

      @@ComputerVisionEngineer It worked! thank you so much

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

    What is util here, it isn't available for me?

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

    Can I know what is this software using coding ?

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

      Hello Pasindu, I am not sure if I understand your question, what do you mean? In this video I show you how to detect colors using Python and OpenCV using the HSV colorspace.

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

      pycharm

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

    Great Video! Could you tell me how the code performs

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

      Hey Johannes, I would say the color detection is performing very well! 😃💪

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

      @@ComputerVisionEngineer do you think I could run it on a raspberry pi zero 😂

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

      As long as you can run Python, install OpenCV and get images from a webcam it 'should' work. If you try it on a raspberry pi let me know how it works! 💪

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

      @@ComputerVisionEngineer yes it would be possible to run it but I would need at least 30fps which I don’t think is realistic on a weaker pi.

  • @warriorlele5523
    @warriorlele5523 6 หลายเดือนก่อน

    awesome video man

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

    hey i tried to follow along with your tutorial but for some reason when i try to run it it says IndexError: index 10 is out of bounds for axis 0 with size 1 how can i fix this ?

  • @sanamakbari1370
    @sanamakbari1370 9 หลายเดือนก่อน

    Thank you

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

    very useful. How can i use this code to detect red color object

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

      Hey, define a new variable called red = [0, 0, 255] and use it instead of the 'yellow' variable. You may need to adjust the definition of red in case is not the exact hue of red you are looking for! 😃🙌

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

      @@ComputerVisionEngineer i tried with a new variable. But hue value is the problem I think. Thanks for the reply

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

      @@microcontroller_garage5387 Hey, I have tried using new variable to detect the red color but there is a problem. Did you managed to solve it?

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

    how should i make it recognise the color red instead of yellow

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

      Hey Jerome, try defining a new variable called red = [0, 0, 255], and use that one instead of 'yellow'. If it doesn't detect the exact hue of red you are looking for you would have to see what are the bgr coordinates of the exact color you want to detect 💪🙌

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

      @@ComputerVisionEngineer Hey, I have tried using new variable to detect the red color but there is a problem. Did you managed to solve it?

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

      @@weaamajoor7420 what problem do you have when trying to detect the red color?

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

      @@ComputerVisionEngineer it stop tracking anything.

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

    Plz make a video on how to fix the media pipe installation error: "No matching distribution found for media pipe"

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

      Hey Shamir, please give me more details about your error. What Python version are you using? What is your OS?

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

    did someone know the RGB value for grey things (type road, circuit, ...)

  • @arif-emre-yaman
    @arif-emre-yaman ปีที่แล้ว

    Do you know which array value I should enter for red?

    • @bhavyan24
      @bhavyan24 9 หลายเดือนก่อน

      did you find an answer?

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

    awesome

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

    Very useful tutorial, thanks!
    I would like to know if you could help me with a project. Do you offer paid consulting?
    The concept of the project is to create a system for selecting and separating stones by shade of green using a Raspberry Pi with a camera. The system captures real-time images through the camera and processes these images to detect the green tones in the stones. Based on the shades of green detected, the stones are classified into different groups (1, 2, 3, 4) according to the defined shade scale.
    The image generated by the camera is displayed on a monitor, and each stone is marked with a square that indicates which group it belongs to.

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

      Hey, I may create a paid consultation product soon. Do you need assistance with this project?

  • @baohanquoc7644
    @baohanquoc7644 9 หลายเดือนก่อน

    how to download util , sir

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

    Hi, i need to make a robot that can avoid green and red obstacles. when the robot detect the green obstacle it should go left and when it sees red obstacle it should go right. and I am kinda lost how to make the camera program, can you help me?🥲

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

      Hey, are you working with Arduino? If you are, search for videos on 'arduino color sensor project', there are plenty of videos on youtube which cover the foundations of how to do it. 🙌

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

    Hi.
    Free where i can get utul packages??

  • @stu.5903
    @stu.5903 ปีที่แล้ว

    How do you put a circle dot in the middle of the lemon/color? I'm trying to create a posture and gait analysis thesis with colored markers and get measurements (angles/distance), I want to be able to detect it and put a point in the middle of each markers and connect each point with lines. Hoping for your response, thanks in advance!

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

      Hey, about the circle take a look at cv2.circle function, you can compute the coordinates of the center of the color by inspecting the bounding box coordinates. 🙌

    • @sir.blobfish1528
      @sir.blobfish1528 ปีที่แล้ว

      Hey! Not sure if you still need the code but here it is anyway:
      if bbox is not None:
      x1, y1, x2, y2 = bbox
      cv2.rectangle(frame, (x1, y1), (x2, y2), [0, 255, 0], 5)
      center_x = (x1 + x2) // 2
      center_y = (y1 + y2) // 2
      frame = cv2.circle(frame, (center_x, center_y), 0, (0, 0, 255), 5) # change the 5 to adjust thickness
      just replace the if statement where you draw the rectangle and there should now me a circle in the middle of the object

  • @Ash2Tutorial
    @Ash2Tutorial 3 หลายเดือนก่อน

    OK. I found the link

  • @cormiersierra9810
    @cormiersierra9810 9 หลายเดือนก่อน

    太牛了...附送源代码....老哥你好...能做一个指定区域里的颜色识别监测不

  • @coimbrawebs
    @coimbrawebs 6 หลายเดือนก่อน

    Nice video man

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

    DO I NEED TO INSTALL VSCODE

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

      yes u can use vs code even this ide the one he using

  • @rohitgalani8228
    @rohitgalani8228 7 หลายเดือนก่อน

    Cezar?????

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

    thankss

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

    Hey, is it possible to make it so the code runs the tracking on screen? Im trying to make an extension that runs on my pc on top of all my apps to track certain colors for premiere keyframes. Im not that skilled in coding so was hopping for a little help.

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

      Hey Sergey, you want to track colors in your screen? Sure, it is possible, I guess the code in this project is a good baseline for that. Take a look at PyAutoGUI library, you can use it to take screenshots, for example. 💪💪

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

    9:25

  • @breadan25
    @breadan25 3 วันที่ผ่านมา

    Is there a way to have multiple bounding boxes when there is more than 1 object of the specified color. Currently is makes 1 large bounding box, which inevitably covers more than the expected color?

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

    How can i take pixels of other colors