Control webcam with servo motor and Raspberry pi - Opencv with Python tutorial

We will learn in this tutorial how to control the webcam using a servo motor and the raspberry pi.
Instructions and source code: pysource.com/2019/06/05/contr...
➤ Full Videocourses:
Object Detection: pysource.com/object-detection...
➤ Follow me on:
Instagram: / pysource7
LinkedIn: / pysource
➤ For business inquiries:
pysource.com/contact

Пікірлер: 139

  • @pysource-com
    @pysource-com2 жыл бұрын

    ►► You can Build a Computer Vision software to DETECT and TRACK any Object. → 4-Step FREE Workshop pysource.com/blueprint-workshop-signup/

  • @onojioboardwalk9748

    @onojioboardwalk9748

    8 ай бұрын

    Do you do commissions? Im looking for someone to build a device like this, Based on Raspberry pie. ;. ?

  • @lodwar
    @lodwar4 жыл бұрын

    You are my hero for today. Thank you: i learned that much in all your videos

  • @devue4183
    @devue41834 жыл бұрын

    You are the best for me. Thank you so much for your tutorials.

  • @adlikarim1906
    @adlikarim19063 жыл бұрын

    wow that's fantastic and you made a free tutorial for it. thanks a lot :D

  • @OLebongiler
    @OLebongiler4 жыл бұрын

    Yeaaaaahhhh! Just awesome! It's work! One of the best tutorial for me. Thanks a lot!!! I subscribed to your KZread channel!

  • @aimadesigns
    @aimadesigns4 жыл бұрын

    Thank you for sharing,your videos are really helping me working on my final year project.

  • @simplesyntax2341
    @simplesyntax23415 жыл бұрын

    Great job, i watch your video regular, all are just awesome!!!!!!!

  • @banditboy6444
    @banditboy64444 жыл бұрын

    You are a legend, great video.

  • @tkinter4428
    @tkinter44284 жыл бұрын

    Perfect. Thanks for sharing.

  • @ettiennegerwel6616
    @ettiennegerwel66164 жыл бұрын

    Great! Well done

  • @sapthagireeshdm2383
    @sapthagireeshdm23834 жыл бұрын

    Thank you so much for the video

  • @jathyadharmasena988
    @jathyadharmasena9883 жыл бұрын

    Very nice ! thanks a lot

  • @edwardkim2757
    @edwardkim27572 жыл бұрын

    Man! how do you do this so easily! thumbs up!

  • @ahmetsonmez2972
    @ahmetsonmez2972Ай бұрын

    Allah razı olsun muhterem

  • @hany-tawfik
    @hany-tawfik4 жыл бұрын

    great video, thank you

  • @med6402
    @med64024 жыл бұрын

    dude you are a legend

  • @sudiptachatterjee5862
    @sudiptachatterjee58624 жыл бұрын

    you are great sir.

  • @jasmineluxor1085
    @jasmineluxor10853 жыл бұрын

    Thank you ❤

  • @keyo3945
    @keyo39455 жыл бұрын

    I did that two months ago By face direction Again with your help on dlib Thank you My project was a robot to detect and warn you about unknown people.

  • @Raju-we6ow

    @Raju-we6ow

    4 жыл бұрын

    can you make a tutorial of face tracking.

  • @stardobas

    @stardobas

    4 жыл бұрын

    @@Raju-we6ow face tracking is simple.... but when you will realize that "face" is "faces" and not only your "face"..... you will need face recognition and not only face detection...at this point probably you have just understand that increase difficult and pi haven't much power to real time face detection and recognition... and you may explode 😂😂😂

  • @ramakrishnachivukula9266
    @ramakrishnachivukula92664 жыл бұрын

    Amazing.....very unique and appears to wok better than pixycam. Can it be also connected to picam. Once again awesome work and great educative video.

  • @jackyli6716
    @jackyli67163 жыл бұрын

    super nice bro

  • @josephadamu2723
    @josephadamu27234 жыл бұрын

    hello please i have a question concerning filters (gaussian, median, bilateral and averaging) associated with OpenCV. I have seen some tutorials using gaussian blur for object detection i would like to know why this particular filter is used for object detection, why is it the best and what are the features that differ from other 3 filters that i have mentioned.

  • @bobthegypsy
    @bobthegypsy2 жыл бұрын

    Love the smile

  • @sdknstar601
    @sdknstar6013 жыл бұрын

    Nice...soon you can put object tracking enable...and disable...and some joystick...and...wireless webcam control from other pc...

  • @JoseLuis-tn5qi
    @JoseLuis-tn5qi4 жыл бұрын

    Hi, great work, do you think it is possible that proyect works in the same way with a simple 5MP cam for rpi? thanks in advantage

  • @stevegables3303

    @stevegables3303

    3 жыл бұрын

    Idk if you're still on this or not, as it was a year ago, but I think the Motion package has some AI features. At least motion detecting capabilities. Not sure about facial recognition yet

  • @mahmou6
    @mahmou63 жыл бұрын

    Hi, is it possible to detect object by color same inside an ROI for tracking as well

  • @jijii6310
    @jijii63105 жыл бұрын

    cool !

  • @kodigudlasreenu8602
    @kodigudlasreenu86024 жыл бұрын

    if we write videocapture(0) can the raspberry get the feed from the camera which is fitted to it?

  • @mahmou6
    @mahmou63 жыл бұрын

    Hi, anyone know how to divide the camera capture in order to detect based on frame segments on the camera capture. Meaning, if my width is 100, can I run the same program to detect in cements if 10 pixels for example from left to right

  • @mahaveerjain1813
    @mahaveerjain18134 жыл бұрын

    Can we speed up the moment of ball so that camera moves faster???

  • @tkinter4428
    @tkinter44284 жыл бұрын

    One dislike is from the red object.

  • @rob26r
    @rob26r4 жыл бұрын

    Nice video! Towards the end of the video you talk about a video course about building projects for a working environment (conveyor belt, etc... automation). Have you done them yet? I'm super interested?

  • @pysource-com

    @pysource-com

    4 жыл бұрын

    Hi Rob, I'm working on it hopefully I'll be able to release it just after the summer. Keep folllowing the channel because I will give the announcement as soon as I have a date

  • @rob26r

    @rob26r

    4 жыл бұрын

    Pysource cool thanks. I will stay tuned!

  • @elielkundai1989
    @elielkundai19894 жыл бұрын

    hy, this is motivating..i have a similar project but i want to track something different

  • @alliem7537
    @alliem75372 жыл бұрын

    15:46 When servo stuff starts (timestamp mostly for my own use :> )

  • @sudiptachatterjee5862
    @sudiptachatterjee58624 жыл бұрын

    Sir, Is it possible to move a robot useing object detection in open cv. Suppose if camera looks a BOOK, then my robot will move that direction.

  • @dookieblaster7
    @dookieblaster74 жыл бұрын

    Is there a way to have so it's not just one color and can detect body's and faces? Great video!

  • @nguyenvu6371

    @nguyenvu6371

    3 жыл бұрын

    of course yes

  • @theOnlyandWan
    @theOnlyandWan4 жыл бұрын

    what type of servo motor are you using ?

  • @aayushlakkad9241
    @aayushlakkad92414 жыл бұрын

    how do I get the lower and higer values of a color?

  • @languageofthenature3034
    @languageofthenature3034 Жыл бұрын

    How did you connect servo? Did you use gpio pins?

  • @luqmanharits1456
    @luqmanharits14562 жыл бұрын

    excuse me sir, can i use to motor servo xyz to ??

  • @user-ir1ds5up7o
    @user-ir1ds5up7o3 жыл бұрын

    23:40 모터, opencv 활용 25:59 화면 부드럽게

  • @youcefabderrahmane4256
    @youcefabderrahmane42565 жыл бұрын

    Please can you give me the circuit program and the code when you use two servomotor sg90 with raspberry

  • @genevievehadj-said18
    @genevievehadj-said185 ай бұрын

    Est-ce possible de faire du traking mais avec n'importe quel objet ?

  • @TheEngineersBeatsDeLinge
    @TheEngineersBeatsDeLinge4 жыл бұрын

    Hey my friend. Which camera do you use. I would like to buy the same. I'm doing a problem with opencv on raspberry but my camera is too slow

  • @pysource-com

    @pysource-com

    4 жыл бұрын

    Logitech c922 pro

  • @luiscadenacampos7884
    @luiscadenacampos78842 жыл бұрын

    Hi, I have the adafruit library for the PCA9685, but when I run your code I get an error: from PCA9685 import PCA9685 ModuleNotFoundError: No module named 'PCA9685'. Do you have the library you used for this module? I don't understand why the Adafruit one is not working for me.

  • @rob1_prd880
    @rob1_prd8807 ай бұрын

    how did you found your range of color ?

  • @ajitgadkari127
    @ajitgadkari1272 жыл бұрын

    How can I get the co-ordinates of the detected ball so as to follow it? Please help...

  • @curious_harsha
    @curious_harsha3 жыл бұрын

    Can we do this without a servo hat? i.e. can we do it using GPIO & PWM?

  • @justswedish
    @justswedish3 жыл бұрын

    ModuleNotFoundError: No module named 'PCA9685' ?

  • @whowhooo370
    @whowhooo3704 жыл бұрын

    How to export that pca9685.py mine is getting error message in the line "from ..... Import"

  • @gapguy9564
    @gapguy9564 Жыл бұрын

    Im getting very low FPS probably (0.2) Please suggest me something. Using : pi3b and hpwebcam for face recognition

  • @ajaykushwah6793
    @ajaykushwah6793 Жыл бұрын

    I am doing segmentation by RGB values of the object, and it is running good but the problem is the display shows the segmentation after 8 to 9 seconds when I put the object in front of the camera...I m using RPi 4 b model with 4 gb ram ..please help me to reduce the response time..I m using Logitech USB cam

  • @arcrobotics9982
    @arcrobotics99822 жыл бұрын

    could this be done using raspberry pi zero w?

  • @KunalKhade25
    @KunalKhade254 жыл бұрын

    Hey I am getting this error Please guide me through select timeout VIDIOC_DQBUF: Resource temporarily unavailable Traceback (most recent call last): File "opencv1.py", line 8, in cv2.imshow('Frame',frame) cv2.error: OpenCV(4.1.0) /home/x/opencv_all/opencv-4.1.0/modules/highgui/src/window.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

  • @XavierRamon
    @XavierRamon4 жыл бұрын

    genial

  • @user-xj3yj3vi6e
    @user-xj3yj3vi6e4 жыл бұрын

    Hi thank you for the tutorial what is the model of the small board you attached to the raspberry pi??

  • @user-os1xg1rh4c

    @user-os1xg1rh4c

    4 жыл бұрын

    pca9685. see he imported the library for it.

  • @user-xj3yj3vi6e

    @user-xj3yj3vi6e

    4 жыл бұрын

    thx

  • @althamishn512

    @althamishn512

    4 жыл бұрын

    @@user-os1xg1rh4c why do we use PCA9685 board? , while the motor can directly connect with Raspberry pi

  • @truongao6354
    @truongao63544 жыл бұрын

    I declared a few lines of code pwm.setServo ... not received

  • @jsopdebeeck
    @jsopdebeeck3 жыл бұрын

    Hello, do you know if it is possible to track Hornets in open-field ( OpenCV, RPi4, fixed HD camera, but laser moving) ? I'm not a developper and I desperate to do better than just detecting basic objects. Hornets are fast objects.

  • @timomehlstein879

    @timomehlstein879

    2 жыл бұрын

    Hey, did you manage to come up with something for your project?

  • @oo_wais
    @oo_wais4 жыл бұрын

    can you make a project to detect speed or velocity of an object?

  • @rdoetjes

    @rdoetjes

    4 жыл бұрын

    This is difficult with a single camera, as you need to know the distance to the lens! Something close to the lens moves faster then something further away. If the camera is stationary and the objects are always at a similar distance then it’s easy. You measure the real life distance between two points in the frame and time how long it takes (how many frames) for the object to hit the first point and to hit the second point. I’ve done this with a camera on my balcony that looks to the road across the street. And it calculates the amount of cars a day and the average speed. Speeds aren’t super exact about 10% deviation. But enough for that solution.

  • @nirash8018
    @nirash80183 жыл бұрын

    I am using the RPi.GPIO library. The problem is, that it's not able to update the angle on every frame, bcs you need to put a time.sleep(0.5) after you gave the servo the command to move to an specific angle. Otherwise it will just instantly jump to the next command and never really has time to move. Is there a different way to approach this, without using the PCA9685 library? Bcs I'm not possesing the extra board

  • @pysource-com

    @pysource-com

    3 жыл бұрын

    You could integrate the python Multithreading option, so that one thread will activate the movement of the servo, while the second thread will keep track of the object at the same time.

  • @nirash8018

    @nirash8018

    3 жыл бұрын

    @@pysource-com Thank you a lot for the quick answer! I'll give it a shot for sure

  • @gapguy9564
    @gapguy9564 Жыл бұрын

    I want to increase fps. Its not usable at present. Using raspi 3b

  • @robinsontyrone96
    @robinsontyrone964 жыл бұрын

    What version of OpenCV did you use? I’m using 4.2.0 and I’m having issues

  • @althamishn512

    @althamishn512

    4 жыл бұрын

    OpenCV - 3.4.1

  • @arniqueen5407
    @arniqueen54073 жыл бұрын

    Its really great. Is this can applied to arduino?

  • @amirabbas4720

    @amirabbas4720

    3 жыл бұрын

    kzread.info/dash/bejne/ZG2EraaSmtvTfJM.html try this

  • @jrickyramos
    @jrickyramos2 жыл бұрын

    Can you do the same thing but actually training the raspberry/Jetson on a specific ‘object’ class rather than the color?

  • @Lancasterlitchfield

    @Lancasterlitchfield

    Жыл бұрын

    Hi i am thinking about working on the same. Did you get any sources or materials to do it?

  • @jrickyramos

    @jrickyramos

    Жыл бұрын

    @@Lancasterlitchfield I found a way to do it following the Jetson Nano series in Paul McWhorters channel combined with Sistemas Inteligentes channel. Combined what I learned from both (and this one of course) - the latter is in Spanish though.

  • @Lancasterlitchfield

    @Lancasterlitchfield

    Жыл бұрын

    @@jrickyramos could you give me your mail id so that if i face any issues i might be able to contact you?

  • @khalilullah6776
    @khalilullah67764 жыл бұрын

    how to install cv2 in raspberry? plz guide me?

  • @dikaputra4579
    @dikaputra45792 жыл бұрын

    Good evening sir, i wanna ask you something about raspberry pi I have a project like a color detection using hsv color space. But when i run the program in raspberry the camera like lagging not clearly and smooth for detection, how can i fix this problem sir. Thx

  • @ajitgadkari127

    @ajitgadkari127

    2 жыл бұрын

    Hii can u help me I'm working on a project human following trolley by detecting the colour of shirt/tag of user...I'm not able to get the coordinats and to find the distance between the user n the trolley...

  • @anantatriantamap7987
    @anantatriantamap79872 жыл бұрын

    thank you, sir and I learned a lot from you. but there is some error with my code. i try to write again with my own self with your code as a reference but in ' _, contours, _ = cv2.findContours(color_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) ' I got an error, ValueError : not enough values to unpack (expected 3, got 2) I hope you can help me. thank you

  • @igrisknight941

    @igrisknight941

    2 жыл бұрын

    you should change it to : contours,hierachy=cv2.findContours(color_mask ,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) maybe that can help your problem

  • @farooqshah1536

    @farooqshah1536

    2 жыл бұрын

    you should use this contours, _ = cv2.findContours(frame, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) '# if u dont need hierachy,

  • @zerok8857

    @zerok8857

    Жыл бұрын

    @@igrisknight941 thank

  • @truongao6354
    @truongao63544 жыл бұрын

    i want to program of cam pi

  • @chakithpatil3478
    @chakithpatil34784 жыл бұрын

    how to code if i want to detect face instead of that red ball .. please help me...

  • @theconcheror5691
    @theconcheror56913 жыл бұрын

    Can this project be used with yolov3?

  • @pysource-com

    @pysource-com

    3 жыл бұрын

    Yes, using the DNN module by opencv you can import weights and cfg files of yolo v3, and also yolo v4 and then you can integrate it with the code I've written

  • @amrutkhodanpur4300
    @amrutkhodanpur43003 жыл бұрын

    👍✌

  • @alexoriginals
    @alexoriginals4 жыл бұрын

    Is it possible to use the same code using PC with windows, or Raspbery has some particularity? (not about gpio and servos, just to capture images)

  • @pysource-com

    @pysource-com

    4 жыл бұрын

    Yes, the part regarding the image and color detection works exactly same way on any os (windows, linux and mac)

  • @alexoriginals

    @alexoriginals

    4 жыл бұрын

    @@pysource-com Thank you. I think your project fantastic, I am starting in python just for to learn Opencv. Here In Brasil this knowleges are scarces.

  • @igrisknight941
    @igrisknight9412 жыл бұрын

    how to solve this ? name 'x_medium' is not defined for cnt in contours: (x, y, w, h) = cv2.boundingRect(cnt) x_medium = int((x + x + w) / 2) break cv2.line(frame, (x_medium, 0), (x_medium, 480), (0, 255, 0), 2)

  • @gilles4332
    @gilles4332 Жыл бұрын

    bonjour et un grand merci à vous, j’ai un rpi3 b+ et un Adafruit DC & Stepper Motor HAT pour Raspberry Pi - Mini Kit, je possède également des moteurs pas à pas nema 17, comment intégrer mon chapeau dans votre code, merci d’avance pour votre réponse que c’est, et bonne continuation.

  • @truongao6354
    @truongao63544 жыл бұрын

    You can ask yourself which PCA9685 library you get from

  • @MsBlade16

    @MsBlade16

    4 жыл бұрын

    TRƯỜNG ĐÀO could you find that PCA9685 library ? If you found that library can you share with me please ?

  • @muhammadaminbadali6185
    @muhammadaminbadali61852 жыл бұрын

    hello Pysource, can i request the libarary for PCA9685 in this video

  • @pysource-com

    @pysource-com

    2 жыл бұрын

    Unfortunately I don't have the files of this project anymore. Anyway you should use the library provided by your servo hat. I recommend to get the Adafruit servo hat and use their library.

  • @naveendubey4412
    @naveendubey44124 жыл бұрын

    sir for the program u have shown at 13:00. fr me the camera opens and then within 1s closes automatically. please give some solution

  • @stardobas

    @stardobas

    4 жыл бұрын

    implement try: except: ....this probably happes becouse first frame il black (camera need time to start)... you have to tell your script to ignore capturing error and try again until frame contain your tracking object

  • @josuecoboscantero936
    @josuecoboscantero9363 жыл бұрын

    Where I can find or download the PCA9685 library?

  • @pysource-com

    @pysource-com

    3 жыл бұрын

    You should integrate the library of your servo HAT. I recommend to use adafruit because is the simplest to integrate

  • @mahmou6
    @mahmou64 жыл бұрын

    Hi all, from where can I get the PCA9685 library from PCA9685 import PCA9685

  • @vinayakdodakundi1881

    @vinayakdodakundi1881

    4 жыл бұрын

    Import Adafruit _9685

  • @kcireorenom8430
    @kcireorenom84303 жыл бұрын

    nice !!!! is it possible to do it with an arduino or an esp32?

  • @MsBlade16
    @MsBlade164 жыл бұрын

    Hi, excellent tutorial thank you, can i take your PCA9685.py file please ? Regards.

  • @aayushlakkad9241

    @aayushlakkad9241

    4 жыл бұрын

    learn.adafruit.com/adafruit-16-channel-pwm-servo-hat-for-raspberry-pi/using-the-python-library here is pca-9685 adafruit e used this library and board

  • @koushikdatta5130
    @koushikdatta51305 жыл бұрын

    I am unable to install opencv in my raspberry pi.... would u please help

  • @michealwithington

    @michealwithington

    4 жыл бұрын

    www.deciphertechnic.com/install-opencv-python-on-raspberry-pi/

  • @muhammadalam1752
    @muhammadalam17524 жыл бұрын

    hello I'm alam from Indonesia, I'm very grateful to you because with this video I can get education, but may I ask for help so you make a video tutorial about detecting ripeness of tomatoes? thank you

  • @YazeedAlkosai
    @YazeedAlkosai3 жыл бұрын

    I have a 3D model I need to measure the length, width, and depth of the feature and detect the features as a hole, pocket, planner ..could you help me to do the coding in Open CV with python

  • @ayoubboubou7202
    @ayoubboubou7202 Жыл бұрын

    can this be done with python?

  • @pysource-com

    @pysource-com

    Жыл бұрын

    it's done with python

  • @ayoubboubou7202

    @ayoubboubou7202

    Жыл бұрын

    @@pysource-com i had an erroe that says " _, contours,_ = cv2.findContours(red_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) ValueError: not enough values to unpack (expected 3, got 2)"

  • @rdoetjes
    @rdoetjes4 жыл бұрын

    Efficiënt programming is not his forte :) Using sorted, with reverse is highly inefficient. Because you’ll iterate through the list twice. So a simple one for loop and only keeping the biggest counter is faster. Plus you don’t need to setup an iterator in a for loop and run it only on the first item - winning performance and reducing an instruction. Doing the x_medium definition calculation and then performing the same calculation for the center is bad! Just assign the x_medium to the center. It may seem nit picking but in applications where there’s a lot of processing, this sort of thing. You need to minimize overhead. Python already is slow, you could knock this up in C++ and even then, you’d make it efficient.

  • @hyunew
    @hyunew4 жыл бұрын

    i want to make robot tracking only me like this video by using deeplearning or yolo, how can i do? plz make new video plz~~

  • @stardobas

    @stardobas

    4 жыл бұрын

    yolo is slow on raspberry...for face detection and recognition in real time you need more more more more conputazional power...

  • @stardobas

    @stardobas

    4 жыл бұрын

    I suggest you to try face_detection module on python (It's a module installabe via pip on ubuntu)... i'ts face recognition is perfect and require only one photo... trust me... try it... find and try on google searching "python face_detection module" open pypy ...and have a good time :)

  • @hyunew

    @hyunew

    4 жыл бұрын

    @@stardobas yeah... now i knew, i searched about that, so i am learning about tflite haha, anyway thank you to recomment ))

  • @mahmou6
    @mahmou64 жыл бұрын

    Apologizes for what may be a silly question, in 13:46 , why contours is written like that: _ , contours , _ ?

  • @mahmou6

    @mahmou6

    4 жыл бұрын

    dbader.org/blog/meaning-of-underscores-in-python

  • @whowhooo370
    @whowhooo3704 жыл бұрын

    can you send me your pca9685 files?

  • @brandonstringfellow1041
    @brandonstringfellow10414 жыл бұрын

    Why not just use: x // y instead of int(x / y)

  • @pysource-com

    @pysource-com

    4 жыл бұрын

    Because the pixel has to be an integer, and in case for example the result is .5 , it has to be rounded otherwise you will get error

  • @brandonstringfellow1041

    @brandonstringfellow1041

    4 жыл бұрын

    @@pysource-com I was under the impression that when using //, you will produce an integer, and / will produce a float.

  • @pysource-com

    @pysource-com

    4 жыл бұрын

    @@brandonstringfellow1041 Oh yes sorry, I missed that. Yes you're right, using // as you said is a better solution than using int()

  • @johnanderson9619
    @johnanderson96192 жыл бұрын

    Why are you shooting the video towards the window with the sunlight coming through it? That's why you can't see objects. Horrible camera position. The camera should be facing oposite direction with the sunlight working with the webcam. Sunlight >> Webcam >> Object . Not Webcam >> Sunlight >> Object. Spin the workspace 180 deg. so the sunlight shines on the object and works behind the webcam, not in front of it blocking the objects because the sunlight is shining in the webcam.

  • @talhamunir3927
    @talhamunir3927 Жыл бұрын

    @Pysource _, contours, _ = cv2.findContours(color_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) ' I got an error, ValueError : not enough values to unpack (expected 3, got 2) what to do??

  • @michealwithington
    @michealwithington4 жыл бұрын

    Mine is not working is this using Opencv 2.0 or will it work the same using Opencv 3.0.0

  • @encryptal
    @encryptal3 жыл бұрын

    What is the servo hat called?

  • @pysource-com

    @pysource-com

    3 жыл бұрын

    this is the servo model: mg996r