OpenCV Python Tutorial #3 - Cameras and VideoCapture

Поделиться
HTML-код
  • Опубликовано: 10 май 2024
  • Welcome to this Python OpenCV tutorial. In this video, I'll be talking about cameras and video capture within OpenCV. Specifically, I'll be showing you how we can load our webcam, how we can view that in live time, and how we can manipulate the image from the camera feed.
    💻 AlgoExpert is the coding interview prep platform that I used to ace my Microsoft and Shopify interviews. Check it out and get a discount on the platform using the code "techwithtim" algoexpert.io/techwithtim
    📄 Relevant Documentation: opencv-python-tutroals.readth...
    📝Code For This Series: github.com/techwithtim/OpenCV...
    🔍 Playlist: • OpenCV Python Tutorials
    ⭐️ Timestamps ⭐️
    00:00 | Introduction
    00:50 | Displaying video capture device
    07:11 | Mirroring video multiple times
    ◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
    💰 Courses & Merch 💰
    💻 The Fundamentals of Programming w/ Python: tech-with-tim.teachable.com/p...
    👕 Merchandise: teespring.com/stores/tech-wit...
    🔗 Social Medias 🔗
    📸 Instagram: / tech_with_tim
    📱 Twitter: / techwithtimm
    ⭐ Discord: / discord
    📝 LinkedIn: / tim-ruscica-82631b179
    🌎 Website: techwithtim.net
    📂 GitHub: github.com/techwithtim
    🔊 Podcast: anchor.fm/tech-with-tim
    🎬 My RUclips Gear 🎬
    🎥 Main Camera (EOS Canon 90D): amzn.to/3cY23y9
    🎥 Secondary Camera (Panasonic Lumix G7): amzn.to/3fl2iEV
    📹 Main Lens (EFS 24mm f/2.8): amzn.to/2Yuol5r
    🕹 Tripod: amzn.to/3hpSprv
    🎤 Main Microphone (Rode NT1): amzn.to/2HrZxXc
    🎤 Secondary Microphone (Synco Wireless Lapel System): amzn.to/3e07Swl
    🎤 Third Microphone (Rode NTG4+): amzn.to/3oi0v8Z
    ☀️ Lights: amzn.to/2ApeiXr
    ⌨ Keyboard (Daskeyboard 4Q): amzn.to/2YpN5vm
    🖱 Mouse (Logitech MX Master): amzn.to/2HsmRDN
    📸 Webcam (Logitech 1080p Pro): amzn.to/2B2IXcQ
    📢 Speaker (Beats Pill): amzn.to/2XYc5ef
    🎧 Headphones (Bose Quiet Comfort 35): amzn.to/2MWbl3e
    🌞 Lamp (BenQ E-reading Lamp): amzn.to/3e0UCr8
    🌞 Secondary Lamp (BenQ Screenbar Plus): amzn.to/30Dtafi
    💻 Monitor (BenQ EX2780Q): amzn.to/2HsmUPZ
    💻 Monitor (LG Ultrawide 34WN750): amzn.to/3dSD7tS
    🎙 Mic Boom Arm (Rode PSA 1): amzn.to/30EZw9m
    🎚 Audio Interface (Focusrite Scarlet 4i4): amzn.to/2TjXsih
    💸 Donations 💸
    💵 One-Time Donations: www.paypal.com/donate?hosted_...
    💰 Patreon: / techwithtim
    ◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
    ⭐️ Tags ⭐️
    - Images within OpenCV
    - Image Manipulation OpenCV
    - Image Fundamentals OpenCV
    - Python
    - Computer vision
    - Cameras and video capture
    ⭐️ Hashtags ⭐️
    #OpenCV #Python #CameraCapture

Комментарии • 135

  • @kingchavez152
    @kingchavez152 3 года назад +25

    What the heck i just started learning opencv and i found you channel and you just started uploading tutorials. Perfect lol

  • @barrotem5627
    @barrotem5627 3 года назад +17

    I am about to finish a face recognition project using OpenCV and this appears to be a great series for those who wish to learn the basics.
    Ty so much Tim ! You make a difference for the future generations 😎

  • @sunwukong6268
    @sunwukong6268 3 года назад +9

    Thanks again. Very nice tutorial, I really like these. And I like the fact, that you run into errors and show what could happen and how to possibly handle these errors.

  • @leonvanzyl
    @leonvanzyl 3 года назад +10

    Hi Tim,
    I'm a recent subscriber to your channel. I've been coding now for 13 years, but is new to Python. Your knowledge is impressive young man, and your explanations are crystal clear. Keep up the brilliant work!

  • @cherifboumaiza147
    @cherifboumaiza147 2 года назад +2

    You are great in the way you explain things ! That shows a lot of control to what you do ! Thanks a lot

  • @jameswilkinson8851
    @jameswilkinson8851 3 года назад +6

    I like this series, very easy to follow as always, looking forward to the next one.. Thank You.

  • @MarceloRodrigues-yx3ty
    @MarceloRodrigues-yx3ty 3 года назад +1

    Looking forward for part #4... Thank you for the awesome tutorials.

  • @avivran1198
    @avivran1198 2 года назад +4

    Hi.
    great stuff for opencv beginners. thanks for the goodwill and the work done to make these videos available

  • @brendanhealy7226
    @brendanhealy7226 3 года назад +25

    Great video as always Tim. For anyone who is interested, here is a function to rotate the image to any chosen angle.
    def rotate(img, angle, rotPoint=None):
    (height, width) = img.shape[:2]

    # set rotation point as center of image if not specified
    if rotPoint is None:
    rotPoint = (width//2, height//2)
    rotMat = cv.getRotationMatrix2D(rotPoint, angle, 1.0)
    dimensions = (width,height)
    return cv.warpAffine(img, rotMat, dimensions)

  • @droneguy69
    @droneguy69 2 года назад

    Great tutorials Tim. Keep making them.

  • @abdullatifnizamani6850
    @abdullatifnizamani6850 3 месяца назад

    You explained everything so simply and details

  • @draytonlav
    @draytonlav 3 года назад

    Cool project! Just finished!

  • @HarshanGandamalla
    @HarshanGandamalla 10 месяцев назад

    thank you tim..It's great learning CV

  • @ananthramvijayaraj4554
    @ananthramvijayaraj4554 3 года назад +2

    Love your vids tim!! Excited for the codejam 3 results

  • @NHY6CK
    @NHY6CK 6 месяцев назад

    I had to make some changes to make the code work for me but at the end it did so thanks! I love it

    • @rontarrant
      @rontarrant 3 месяца назад

      Please share the changes you made.

  • @ihatethesensors
    @ihatethesensors 2 года назад +2

    Awesome tutorial man!
    Btw, you can still do it with the 4 different rotations if they are all squares. It looks really trippy...
    Here's the code:
    import numpy as np
    import cv2
    cap = cv2.VideoCapture(0)
    while True:
    ret, frame = cap.read()
    h = frame.shape[0]
    w = frame.shape[1]
    strip = abs(w - h)//2
    edge = min(w, h)
    square = np.zeros((edge, edge, frame.shape[2]), np.uint8)
    square = frame[:, strip:-strip]
    small = cv2.resize(square, (0, 0), fx=0.5, fy=0.5)
    square[:edge//2, :edge//2] = cv2.rotate(small, cv2.ROTATE_90_CLOCKWISE)
    square[edge//2:, :edge//2] = cv2.rotate(small, cv2.ROTATE_180)
    square[:edge//2, edge//2:] = cv2.rotate(small, cv2.ROTATE_90_COUNTERCLOCKWISE)
    square[edge//2:, edge//2:] = small
    cv2.imshow('frame', square)
    if cv2.waitKey(1) == ord('p'):
    break
    cap.release()
    cv2.destroyAllWindows()

    • @hedimak999
      @hedimak999 2 года назад

      yooo dude thanks , im learning facial recognition and rotating 90 deg angles is needed for that , thank you for your addition.

  • @shaulchamoula4863
    @shaulchamoula4863 3 года назад

    Hi Tim, Thank you SO much,
    What do you think of alpr (Automatic License Plate Recognition)? First recognize plate/s then recognize digits in plate.

  • @KSATica
    @KSATica Год назад

    thank you thank you your video tutorial helped....

  • @TopMusic-rw3yz
    @TopMusic-rw3yz 2 года назад

    Great tutorials!!!!!!!!!!

  • @jollokim1948
    @jollokim1948 3 года назад

    This is awesome

  • @pranitg2039
    @pranitg2039 3 года назад +1

    15:30 Tim, Can we somehow make use of the .T Attribute of numpy ndarray so as to swap the the height and width?

  • @vatsaplaysguitar
    @vatsaplaysguitar Год назад

    amazing tutorial tim, im not getting the auto predict/ complete thingy in my sublime text like you, how do i enable/fix this?

  • @alijebrailzade7439
    @alijebrailzade7439 3 года назад +3

    Hello Tim can you make a video "python STATIC TYPING with mypy"? It turns dynamic language to complete static language.

  • @steventeasdale9082
    @steventeasdale9082 4 месяца назад

    Hi Tim, I know you did these videos a few years ago now, but I am just starting out with OpenCV and have begun watching your videos, I don't have a "webcam", is there anyway I can use the camera attached to my Raspberry PI 4/5?? Do I need to SSH into my Pi? Any help much appreciated!! Great videos, keep em coming

  • @omereid7525
    @omereid7525 2 года назад

    THANKS VERY GOOD

  • @HipHop-cz6os
    @HipHop-cz6os 3 года назад +3

    Will u upload videos on object detection using yolo?

  • @Chorum1975
    @Chorum1975 2 года назад

    Really nice video! May you explain how to get that video into a Frame or Label without using Pillow? If i use Pillow the video is very slow ...

  • @rafiksalmi2826
    @rafiksalmi2826 16 дней назад

    Thank you

  • @harshalghatol4182
    @harshalghatol4182 3 года назад +1

    A quick question ,could we have also used frame.shape[1] instead of cap.get(3) as well as for height? if we could or could not , can you please justify.Thank You for such a good video.

  • @itsjxelito
    @itsjxelito Год назад +2

    use cv2.VideoCapture(0, cv2.CAP_DSHOW)
    If cv2.VideoCapture(0) is taking awhile to display webcam

  • @viveknayar8677
    @viveknayar8677 2 года назад

    Hey, so why did we not create a canvas or array when displaying video capture device?
    ps: great video!

  • @moralexbme
    @moralexbme Год назад

    Thank you for this tutorial! I am using a fisheye camera with multiple viewing angles where i can change then number in the link (cap = cv.VideoCapture('blablabla/mjpg/4

  • @CodingWorm
    @CodingWorm 3 года назад +10

    Part 4 Coming Soon, he should have said

  • @pranaygundu
    @pranaygundu 3 года назад

    hey "tech with tim youtube ":) , I just started open cv course and I am really enjoying it :).
    but should I need to master the math behind openCV functions ???? to be a good programmer .........whatever :) ...........

  • @xinglinjiang4952
    @xinglinjiang4952 2 года назад

    at what point the physical camera start to work? i am try to precisely control the starting time of two identical cameras so they can be frame synchronized. first i would like do it by software. but i can also div the hard ware (the easist way should be starting the power supply at the same time by a shared switch).

  • @dhxbcmd
    @dhxbcmd 2 года назад

    thank you for your lecture
    wonder
    Start video recording key = 'F5'
    Video recording pause key ='F6'
    End section (off) key ='q'
    If you can tell me how to do it, thank you.

  • @lessonscript
    @lessonscript 2 года назад

  • @aaravgp1332
    @aaravgp1332 3 года назад

    how can we record the video into another video or screen share using openCV or add frames to an existing video.

  • @Nikiwe_
    @Nikiwe_ 2 года назад

    Thanks a lot Tim. How do I use a different camera, for example, proscilica cameras. Do I have to use its IP address like cv2.videocapture(‘IP address’)? Or do I have to say cv2.videocapture(1)?

    • @Meganano
      @Meganano 2 года назад

      the first if it doesnt connect via usb👍

  • @oOWaschBaerOo
    @oOWaschBaerOo 2 года назад

    i have one big issue with open cv, in that i cant change the size of the resulting window manually, by dragging the sides or clicking on maximize, is there a way to achieve this with open cv ?

  • @MK-vd4yx
    @MK-vd4yx 2 года назад

    Nice T-shirt buddy

  • @electronicmag16
    @electronicmag16 3 года назад

    Is there a better way to select the devices than by arbitrary number? Like for instance by name of the device or usb port of the webcam?
    I had looked into it but I could only find python-c++ solutions, which were effective, but rather complicated...
    Wondering if you knew a better solution Tim. Thank you :D

    • @Aminoquiz
      @Aminoquiz Год назад

      Hi, did you find one ? I can't figure which number is my plugged-in webcam...

    • @adanflores4410
      @adanflores4410 Год назад

      @@Aminoquiz me too, now you know?

  • @py_tok5589
    @py_tok5589 3 года назад

    LOVELY

  • @josuenlandu8907
    @josuenlandu8907 2 года назад

    Thanks a lot Tim for all.
    I have a concern about Third video : OpenCV Python Tutorial #3 - Cameras and VideoCapture.
    When I run the code, the webcam opens, but only for a fraction of a second.
    I send the capture in the appendix.

  • @bhavyanshsharma3925
    @bhavyanshsharma3925 Год назад

    can anyone help???
    i am not able to access my video......there's just an orange screen in the frame window but not the video

  • @jn7071
    @jn7071 2 года назад

    Hi, I am now to Python, which platform you use to run the python script?

  • @madstudios1688
    @madstudios1688 Год назад

    how can i make my own python 3d camera tracker?
    i want to learn how extract camera motion data from imagine sequence and use it in a 3d program

  • @kouseiarima8805
    @kouseiarima8805 Год назад

    Is it possible to access another e.g. camera of another pc, like you are the admin and accessible only to you?

  • @ahmedzia7000
    @ahmedzia7000 Год назад

    HI! How can i save a video without displaying the video on monitor i tried commenting out cv2.imshow and also the waitkey but it saves the video which doesnot open like sort of a damaged file

  • @subba5735
    @subba5735 2 года назад

    Can you please make video about black background on image

  • @akshayshrivastava6057
    @akshayshrivastava6057 2 года назад

    how we can access the camera after deployment of our app please make another tutorial regarding this how to get the link we could use it in our videocapture

  • @ersinbardakc
    @ersinbardakc 2 месяца назад

    I am mirroring android phone screen to pc. Can I use that screen for opencv ?

  • @ico-theredstonesurgeon4380
    @ico-theredstonesurgeon4380 3 года назад

    how does that comma in the square brakets work?

  • @justwatchv
    @justwatchv 3 года назад

    ❤️❤️❤️

  • @adityapradhan7201
    @adityapradhan7201 3 года назад

    I press q, the window is destroyed but cap.release() doesn't free up my webcam resource. Can you tell me what could be the issue here?

  • @mrtechtonics2209
    @mrtechtonics2209 Год назад

    Hey which IDE do you use?

  • @unsalpisirgen9204
    @unsalpisirgen9204 2 года назад

    how do i count people passing by a camera
    can you help me with this.
    The camera is looking at people from above and I want to count the people passing under it. How do I do it?

  • @duygukocar7623
    @duygukocar7623 Год назад

    Can I use Ip camera port and ip address in 2:12 ? Can I record some part of Ip camera video?

  • @yashwanthj9305
    @yashwanthj9305 11 месяцев назад

    I am getting error has no attribute video capture in cv2 module how to overcome it

  • @loarddragongammer941
    @loarddragongammer941 9 месяцев назад

    when heared as key i heared ass key that got me crakin' up

  • @klintkrossa6885
    @klintkrossa6885 3 года назад +2

    I would like to display current temperature on a black back ground. how do I make an infinite loop black screen? Then how do I add the text?

    • @jonasstrabel
      @jonasstrabel 3 года назад

      Why would you use cv2 if you just want to display text with black background?

    • @klintkrossa6885
      @klintkrossa6885 3 года назад

      @@jonasstrabel to have a display for a webpage that is dynamic, like temperature.

    • @jonasstrabel
      @jonasstrabel 3 года назад

      @@klintkrossa6885 I don't thing open cv2 is the way to go for that matter.

  • @technohub4348
    @technohub4348 2 года назад

    Hey @Teach With tim please help me with this problem
    opencv camera frame black !!

  • @PhoneArtistry
    @PhoneArtistry 6 месяцев назад

    I write the same code and trying to play a mp4 video but it will constantly giving me an error. And I can't fix that. The error is:
    cv.imshow("frame", frame)
    cv2.error: OpenCV(4.8.1) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:971: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
    please help me with that if anyone can

  • @ahmed.m.haniya
    @ahmed.m.haniya 3 года назад

    👌👍

  • @vandanapal3011
    @vandanapal3011 2 года назад

    how to capture image and import then convert sketch in python can u send source code

  • @sfvarandas
    @sfvarandas 3 года назад

    I have no image, only a black box. I don't know why. My webcam lights up but no image.

  • @adityak1231
    @adityak1231 3 года назад +1

    I'm getting an error at 5:56
    Abort trap: 6
    It is not exactly an error. It has been handled by cv2 I think. How do I fix this?
    PS: I'm on MacOS 11

    • @mohan_hamal
      @mohan_hamal 3 года назад

      The problem seems to be for macOS. Check StackOverflow, there seems to be a solution there.

    • @adityak1231
      @adityak1231 3 года назад

      @@mohan_hamal Yeah it is because of the privacy settings. It runs properly when executed through the Terminal.

    • @magicmagus1459
      @magicmagus1459 3 года назад

      @@adityak1231 yes same for me. code works when running in terminal. Did u find a way for it to work when running through sublime text?

    • @adityak1231
      @adityak1231 3 года назад

      @@magicmagus1459 I haven't figured out a way to do it. I don't even think it can be done because in the privacy settings it doesn't show the option of allowing camera access to VS Code. Idk about Sublime because I don't have it. You can check in System Preferences if you want to.

  • @kilovolt2494
    @kilovolt2494 2 года назад

    why in the world did they do it like this? What was the problem to created .get_width() method?

  • @kashyapsantoki4889
    @kashyapsantoki4889 3 года назад

    I think no one got heart from Tim. But this ❤️ is for u Tim from INDIA.

    • @binaprajapati3593
      @binaprajapati3593 3 года назад

      Not true, I had got heart from tim, and me too from india

  • @Pradeep_Rai_Thota
    @Pradeep_Rai_Thota 3 года назад +1

    Please let me know which the screen recorder you are using to create videos

  • @tomherbert5396
    @tomherbert5396 2 года назад

    Is this possible thru a browser?

  • @corydkiser
    @corydkiser 3 года назад

    object detection pls

  • @howarddelosreyes463
    @howarddelosreyes463 2 года назад +1

    OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'imshow'
    anyone else having this issue?

  • @dasturlash7266
    @dasturlash7266 2 года назад

    Omad Okalar Omad !

  • @scotttresor
    @scotttresor 3 года назад

    i have this problem how can i resolve this

  • @superbrokeengineer
    @superbrokeengineer 3 года назад

    Could u tell me my pycharm can’t use VideoCaptue

  • @jyothishmohan5613
    @jyothishmohan5613 3 года назад

    Try this for 2nd and 4th quadrant upside down..........
    image[:height//2,:width//2] = smaller_frame[::-1]
    image[:height//2,width//2:] = smaller_frame
    image[height//2:,width//2:] = smaller_frame[::-1]
    image[height//2:,:width//2] = smaller_frame

  • @parth2teja
    @parth2teja 3 года назад

    Exact 1000th viewer and 100th liker

  • @anaymittal7720
    @anaymittal7720 2 года назад

    How can I take a picture instantly without the window opening?

  • @Life-zx5wp
    @Life-zx5wp 3 года назад

    AttributeError: module 'cv2.cv2' has no attribute 'videoCapture'
    i got this error and it's not working

  • @binaprajapati3593
    @binaprajapati3593 3 года назад +2

    5th I guess

  • @fareedzafar813
    @fareedzafar813 11 месяцев назад

    documentation link is dead....

  • @gustavojuantorena
    @gustavojuantorena 3 года назад +1

    First :D

  • @prasannan-robots
    @prasannan-robots 3 года назад +2

    Second

  • @harish884
    @harish884 3 года назад

    Which ide do you use

  • @coolghoul9
    @coolghoul9 17 дней назад

    you made stereograms

  • @darthkroxis
    @darthkroxis 3 года назад

    Tim go realize in the video the SLAM method

  • @feraudyh
    @feraudyh 2 года назад

    Would it not be better to get the width and height before the loop?

  • @RedHeadphone
    @RedHeadphone 3 года назад

    What if don't cap.release()

  • @kimkong1668
    @kimkong1668 3 года назад

    Is it just me or does Tim look like Meelo from Legend of Korra?

  • @jeferson1556
    @jeferson1556 2 года назад

    Which app is he using

  • @naveen.m9847
    @naveen.m9847 3 года назад

    How to make simple app with python

  • @tanishtyagi1301
    @tanishtyagi1301 3 года назад

    first

  • @aprameyamandal4346
    @aprameyamandal4346 3 года назад

    Third

  • @alpanamhashilkar960
    @alpanamhashilkar960 3 года назад

    760th viewer

  • @raffayirfan
    @raffayirfan 3 года назад

    hello

  • @flextapemyass
    @flextapemyass 3 года назад +7

    Girls: Python is so booooring
    Guys: 16:48

  • @NinjaAhmed-cp3pe
    @NinjaAhmed-cp3pe 3 года назад

    8th

  • @erfansadeghinezhad9780
    @erfansadeghinezhad9780 3 года назад

    Forth😂

  • @khang-jm4pm
    @khang-jm4pm 3 года назад

    this is kinda complicated actually