AI for Everyone LESSON 5: Installing OpenCV in Windows and Launching WEBCAM
Вставка
- Опубліковано 2 сер 2021
- You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:
/ paulmcwhorter
In these lessons we will be using a logitech webcam. If you use the identical camera that I have, you will be ensured to get the same results. I suggest your life will be easier if you use the same camera I am using, available from Amazon below:
amzn.to/3iwgIW0
In this video I show how to install opencv on windows, and how to write your first opencv program. We will show how to grab a frame from the camera, and then show it using cv2.imshow.
[Disclosure of Material Connection: I am a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com. This means if you visit the link and purchase the item, I will receive an affiliate commission. Regardless, I only recommend products or services I use personally and believe will add value to my readers.]
#ArtificialIntelligence
#Python
#VisualStudioCode - Наука та технологія
After I had installed the webcam it did not work , the program crashed and I kept getting this error "[ WARN:0] global C:\Users
unneradmin\AppData\Local\Temp\pip-req-build-uzca7qz1\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback" until I found out that I had Windows to grant apps access to the camera . May be this helps some reader who watches this series some time in the future.
How did you grant permission?
I am getting [WARN:0] global C:\Users
unneradmin\AppData\Local\Temp\pip-req-build-uzca7qz1\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
Traceback (most recent call last):
File "c:/Users/John/Documents/Python/openCV-1.py", line 6, in
cv2.imshow('my WEBcam',frame)
cv2.error: OpenCV(4.5.3) C:\Users
unneradmin\AppData\Local\Temp\pip-req-build-uzca7qz1\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
I found success using this as the set cam code "cam=cv2.VideoCapture(1, cv2.CAP_DSHOW)"
@@johnstephenson4428 go to ur camera settings and allow access to i guess the visual code app
There is no option to give permission to use the webcam to visual studio code. It all works until i try to move the window
Paul, I have to tell you that your lessons are absolutely top quality. You have taught me C++ and Autodesk Fusion 360 over the last years. This has enabled me to build a small booby trap 'detect and disable' robot for future use by the HALO Trust in Syria, clearing booby trap IEDs in buildings. (It's currently undergoing evaluation exercises before being shipped out to Syria.)
I have a couple of ideas for using AI so am now following this course.
The African Queen is a great movie. You are a great teacher. And I am excited to learn more of the possibilities using AI. Thanks
Oh, a top tip from me. Put your hot coffee into a cocktail shaker with ice cubes and shake vigorously.
Wonderful explanation about an important topic.
The next awesome lesson. And so easy to follow while providing insights into really important basics of version control that I was actually struggling for a long time (virtual environment and corrupt programs due to a mess of various libraries). From crucial fundamentals right into coding (also like Visual Studio Code while used pycharm before that). Brings me so much joy during the weekend! - Keep on going with those videos - AfricanQueen
Just how wonderful.. I really like you and your STUFFS
Paul. Just gotta say it again, you're an amazing teacher! Even after I apparently missed the installation of python 3.6.6, I still managed to find it, install it, set up virtual environment, and set up visual studio python interpreter on my own. NOW, I'm ready continue watching lesson 5.
Great to hear!
African Queen!
I have finished the lesson, and next trying to solve the home work.
Thank you Sir.
Learned Arduino from your channel and right when I needed a tutorial for OpenCv, here you are Mr Paul McWhorter with your great content. Thank you so much :D
Thank you. African Queen. I painfully managed to run Visual Studio Code in my Macbook.But now I can follow the rest of the class.
I finished the homework to perfection. African Queen.
Sir. You are a good teacher. 👍
Hey Mr.McWhorter,
Thank you for taking the time to make these thorough lessons. I've went through some of your Raspberry Pi tutorials, so I'll be excited to take the knowledge from here and apply it to the Pi. These videos have been helpful to me in career switch. I originally did my undergrad in social work, but now I'm doing a master's in computer science. I'm thinking that I want to go into embedded systems. But I do really appreciate how thorough these videos are. I've watched other OpenCV tutorials that weren't quite as thorough, and I felt like I ultimately didn't learn a whole lot.
Hi Paul, "African Queen". Another great tutorial. I got the homework done okay but I got myself down another "rabbit hole" trying to incorporate Multiple Processing for each frame: I think I'll just park that idea for now and move onto the next tutorial. Thanks again.
African Queen. And I am legend! I am just now getting to these lessons, so I got some catching up to do, but will. Great video as always Paul!!
Wonderful!
Copy & paste is soooo useful - you can duplicate a typo so often, so accurately, as many times as you want. But my windows are too big to prevent overlapping without manual resizing.
I remember a few scenes from African Queen but not much more. It's great when history floats on past - I was on the Murray River quite a few years back and a paddle steamer towing barges went by on some event re-enactment. Just a few km downstream from where we were staying, there was a 'special' section of river (a hand-dug cutoff, that shortcut something like 12 km of river loop, so you can imagine the current through
Thank you for this class.
Always welcome
I AM LEGEND! I also played around with resizing the windows and showed video from both the Logitech camera and my laptop's camera. As usual, thanks for the most excellent lessons Paul.
Fantastic!
Thank you Paul !!!!
African Queen. I learnt a lot from your arduino series . I even used an arduino to program an atiny85 which I used in my rc Bluetooth remote car.Thanks🙋🙋
It is great when things run like they should first time (barring typos, of course)
African Queen
I am having a great time following these videos. So far, your instructions have performed flawlessly. I am now going to try to do this using a linux virtual machine. Wish me luck!
Thanks Paul!
Another great lesson Paul. I've got 2 frames each appearing twice @ 0,0, 640,0, 0,480 and 640,480. Needing unique names for the windows banners caught me at first but I am legend. So is the African Queen. Bogart at his surly best.
Managed to follow the lesson on my raspberry pi 4, 8 GB version, 64 bit OS.
I use python 3.7.9 and it works fine so far with openCV. It seems quicker than your windows version as well, approx 5 sec from I click "run" till the windows show (managed to get 6 windows with different "filters") on my screen. Noticed latency increase as windows were added ... ;-)
Loved the African Queen movie. See ya tomorrow, Paul.
Hi Paul I succeeded to make it so I am a legend. But I did your assignment run Mac OS Catalina and using my integrated camera. Setting the environment was a bit different but so far so good, donut.
Thanks for your fantastic tutorial
Nice work!
African Queen! Thanks a lot for another great tutorial! For mac and linux users, replace
cv2.VideoCapture(0)
with:
cv2.VideoCapture('/dev/video0')
Don't know what difference it makes, seems to be faster on my machine, and on my raspberry pi, VideoCapture(0) doesn't seem to work for some reason even though it works on my Ubuntu 20.04 main computer, albeit slowly.
Thanks for sharing!!
I am legend
African Queen
Paul! You were born to teach.
I have had it on my priority list to get started with AI for like half a decade.
You might just end up being responsible for me actually doing so. (single handedly I may add)
By the way, I have played around with openCV + np + ctypes and in the end I have stacked the frames first horizontally in upper/lower rows, then stacked the rows vertically. Then I got one unified window which I've resized according to my current screen, so when I move it to another screen, it adjust to the active screen. Nice shit. 🙂
At present I am also about half-way through the AI on Jetson Nano series, so getting into familiar waters here on openCV. I suppose at some point we will reach the rapids just as the old African Queen did. I am thoroughly enjoying both series! Very nicely done...
This then will be review for you for a while, but then I will take this a different direction in future videos.
Thank you Paul for all your classes. I fold up like a cheap Walmart lawn chair all the time, but it's fun trying. One of the questions I have and I understand that you may not be able to answer, but in all the while true loops throughout this course, you have code that moves images or creates other ROI and more moves in the loop. To me it sounds like every time thru loop it has to do all these moves, that the frame may be somewhere for a split second and them get moved. The eye cannot see this I suppose, but would it be better to create the windows outside the while loop first, then use the windows in the loop? Is this an engineer question? Maybe you suggest this in latter lessons. Anyway, I really learn a lot from your classes. Thanks
African Queen! Watched it many times. Home work done, bur sorry I miss it at 11:30 EST.
Hi Paul, loving this series. Followed your Jetson AI course also. Out of curiosity will this Opencv - python install access my gpu? Or will all the calculations be done on my cpu?
oh yeah... Africa Queen ;)
thank you very much for your effort
So nice of you
African Queen: Hi Paul, your masterstroke with your tutorials is the way you explain what versions of the software you used and how to set up an environment that will use those versions. Too many UA-camrs show you a tutorial that worked, say, two years ago and now they won't because the software has been updated. This should mean that your tutorials will have a longer useful life. Thanks.
Absolutely agree! Got into programming due to his tutorials, and the fact that stuff just works without me having to spend hours trying to find solutions to problems all over the internet. However, I think it's good to try and update packages and python versions to latest after you've got it working on the version Paul is using at this point in time. For example, I'm on Linux and running all of this on Python 3.8 and latest version of all packages, and everything runs perfectly.
African Queen. Just for info I was able to install opencv using pip directly from the terminal window of vscode into the venv. Also added the opencv intellisense extension which seems very good.
African Queen. My camera has arrived!, looking forward to more lessons.
Had trouble with my code before watching this, had everything right but out of order. Thank you, leaving this message for the algorithm. Almost forgot the African queen
Great to hear!
African Queen !
Great Lesson,Thank you Professor !!
It works fine for me to use the build-in webcam in my Laptop. But when using my old USB webcam from Logitech, it take many many seconds before the camera starts to work. I was about to kill the program first time I tried, but then it started to work after 10 seconds. Once it started, it works fine.
I appreciate your use of virtual environments and recommend replacing the steam engine on the African Queen with an outboard with some serious horsepower, the better to evade rapids.
Fun Project, Challenge wasn't too bad. African Queen
African Queen!!! Got everything working as long as I leave the cam release part out..
if you do not have a webcam and you want to fully participate in the tutorials, you can look for how to use your phone as a webcam. I'm doing this rn and works really well
all working so far.
using helios 300 laptop with the same logitec cam
does take a good 30 secs to show the screen. AFRICAN QUEEN
Thank you Paul, please if you explain why we put "& 0xff" after the waitKey() , African Queen
African Queen. You are awesome, Sir. Thank you very much for your great work as always!
So nice of you
African Queen. Legend status claimed-done homework-4 on one page as requested. You explained this lesson so well that even a non IT 77 year old could understand
I did the homework and took it a step further by adding a third coloured frame and a third grey frame
So, this assignment should be easy for me since I've gotten most of the way through AI on the jetson nano! (I still gotta go back and finish that series too). African queen!
It is actuallly good to do both series. Sometimes the second time through things reallly begin to make sense and stick.
What is the difference between a command prompt and Windows Powershell?
AFRICAN QUEEN! My wife hates it when I watch those old movies but I love them. Hmm, Mr. Arnott was Boggie's character but I'm having a senior moment for the character Katherine Hepburn played. I believed he called her miss through a lot of the movie. I also can't remember what his first name was. I know she asked him at one point. Talk about digressing! I haven't gotten my web cam yet but (0) ended up being my laptop camera. These commands are very tricky and if you miss one little thing forget it.
I rarely watch movies, but when I do it is an old one. Probably my top ten all time favorites
1) Ben Hur (original Charleton Heston one)
2) Tombstone
3) Braveheart
4) Ten Commandments
5) Master and Commander
6) King Arthur
7) Gladiator
8) Count of Monte Cristo
9) Signs
10) the Village
11) The Prestige
12) Passion of the Christ
13) Second Hand Lion
14) The Alamo (One with Billy Bob Thorton)
15) Back to the Future
16) The Outlaw Josey Wales
17) The Good the Bad and the Ugly
18) Silverado
19) Crocodile Dundee
20) Moonraker
OK, I lied, that was 20
I Am Legend.
I struggled a bit, but managed to get working.
Video works for 2 seconds or less the goes away code seems correct???
Very good explanation. Thank you -- African Queen
Glad it was helpful!
I found my issues i loaded some thing you didn't include and that what lead to my problem, i have fix them now.
Awesome lesson as always ! I was afraid that my web cam won't start becouse it's the same but he kick it on a first attempt. And off course : African Queen.
😀
Please teach Django as well
HEY PAUL ; whenver i try to install open cv i got this error SSL: CERTIFICATE_VERIFY_FAILED .... any help please ?
Hey Paul, aprreciate your videos very much. I have an issue with intellisense for cv2 - it simply doesn`t show almost no hints. I tried installing and uninstalling it. Did not help. Do you know what could be the reason?
IT is a constant battle to get intellisense to work with cv2. as VS code upgrades, and as cv2 changes, seems it always reaquires a new tweak to get things working.
@@paulmcwhorter Thanks. Had to upgrade cv2 to latest version for intellisense to work properly.
African queen!! Your lessons are awesome Sir🙏
Thank you! 😃
Your class is truly engaging, Paul. As someone transitioning from Java and C++, I must admit I harbored some reservations about Python. However, your instruction is reshaping my perspective :)
I do have a question: Will this approach remain applicable in Python 11 when using the latest version of OpenCV?
Thank you very much!
African Queen
PS: Till now, everything is working just fine with my laptop camera.
I do have some weirdness. If I run a python program in the 3.6 venv that has an unused variable, it crashes with segmentation fault. I don't think that will be a big deal. The other environments are fine To be honest, the 3.6.9 programs from my jetson run on 3.9.6 anyway as far as I can tell. So if it does turn out to be a problem, I will try it in a different interpreter before worrying about it.
African Queen..... good lesson...onward and upward
African Queen! Thanks for the lessons Paul
A couple notes:
The logitech cam is slow as molasses in January, takes at least a minute before anything comes up. But the built-in cam on my laptop displays results in about 5 seconds, so I'm better off using that.
I had 2 windows displaying the results in gray and color, but then for no reason I can see they just show pure black windows now. I googled but haven't found an answer for this.
Add note: in the next video Paul shows tips that make a huge performance improvement, and now I can use the webcam that he recommended. Very nice!
African Queen! So nice lecture Paul
if anyone knows how to fix this, I am having a problem where intellisense on vscode doesn't work when I use the new interpreter
BOOM ... well, sort of!
I'm unable to use python 3.6 - 2 years on from these tutorials it's no longer available.
However, I've carried on using python 3.7 and so far seems to be working OK.
Initially I thought the python program wasn't working until I realized the webcam window was opening in the background ... so I had to go looking for it. Also, it was taking about 1-1/2 minutes for the screen to appear - gradually increasing to 2-1/2 minutes as I attempted the 'homework'. Didn't finish the latter due to the delays but I get the general idea ... I'll catch up with that in the next video. Perhaps my laptop is due for a reboot.
African Queen!
You can't beat Humphrey Bogart and Katherine Hepburn on the African Queen. Great job!
The boat "African Queen" was built in England in 1912 and used by the "British East Africa Company" from 1912 to 1968. 👍
I uninstalled VSCode completely and reinstalled it with 0 extensions then installed the same version of Python (v2021.7.10....895)you had for IntelliSense autosuggestions to appear
African Queen. Thank you. Great lesson today.
Hey everyone just a heads up, so i got an error saying “if cv2.waitkey(1) & 0xff == ord(‘q’):
AttributeError: module ‘cv2.cv2’ has no attribute ‘waitkey’
I was worried because i am using a dell laptop using the webcam that is on the laptop, i am using “camera 0” so first i tried flipping through the numbers 0...1...2...3 and nothing worked. Then I noticed that i did “waitKey” wrong... i did not have the K capitalized. Make sure you do that. After I changed the K it started to work for me.
how can i make the window with the camera footage smaller so that 4 of them fit on the screen
Will be covered in the next lessons. Stay tuned.
african Queen... thank you... your code is runing ok on mi desktop.
african queen! awesome series so far, just as always
Glad you like them!
Hello Paul, I could not locate the 3.6.6 64-bit('pyAI3.6':venv). I found the others for 3.7 and 3.9. I have repeated the steps several times, but no success. Maybe you can advise. Thank you.
Did you create the venv? if you did and it is not showing up, stop visual studio and restart it.
@@paulmcwhorter Thanks for the prompt reply. Solved.
Hi Paul sir ! The word is African Queen.
I am legend (in an orange sweatshirt as I' m doing the 3D Graphics as well). I just guessed the coordinates of the windows and then adjusted them. There must be a better way, maybe the answer is on the African Queen.
i also guessed lmao
I'm using Python 3.9.6 on Ubuntu20.04 with a Logitech camera and that is working fine. :-)
Using python 3.8.6 on 20.04 with builtin camera, everything works.
African queen. I still am stuck on changing my directory to the folder that contains my VENV's, when I DIR, Into documents it shows nothing. I've been stuck on that this entire time, Can you suggest some possible fixes please?
Thanks Paul, Great Stuff!! African Queen.
Thanks for listening
Did the homework. African Queen.
Hey Mr Mcwhorter, I know I should have asked this earliar but what does the -m do while creating a virtual environment?
please sir the difference between Machine learning and Deep Learning
African Queen. Thank you sir the lessons are as great as always
Thank you! 😃
African Queen and I have done my homework all ready
I brought a C920 webcam today! (169 dollarydoos here in Australia). Works much better than my built-in laptop camera. Completed my homework ok. I had to resize images to fit on screen and, after some research, I used:
cam.set(cv2.CAP_PROP_FRAME_WIDTH,320)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT,240)
African Queen!
Shhh . . . that is coming up in next lessons.
omg i thought it didnt work coz im in a random laptop but i just havent put the >>quit() thing in the terminal silly me
african queennnn
i knew u were gonna make us do it all again. was scared cuz i was just copying u.
thats actually my prob w the other tutorials tho. they dont give hws like u which means i dont feel pressured abt knowing how to do it by myself loll
ill do it now
EDIT: FINISHEDDDDD! i am legend
African Queen - Thanks for a very clear tutorial👍
Glad it was helpful!
between Read a frame and show a frame and that's where the magic happens
Indeed!
AFRICAN QUEEN
After arduino, I'm here to learn more about AI and robotics
African Queen ... Mr. McWhorter :)
i used the webcam of my laptop and i have the following error.
[ WARN:0] global C:\Users
unneradmin\AppData\Local\Temp\pip-req-build-uzca7qz1\opencv\modules\videoio\src\cap_msmf.cpp (691) CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (640x480 @ 30) MFVideoFormat_RGB24(codec not found)
To fix it i use the instruction cam=cv2.VideoCapture(0,cv2.CAP_DSHOW) insteqd of cam=cv2.VideoCapture(0) and it work
In future lesson we will show how to set codec. Logitech cam works without it, but we will learn about this.
Great video, thanks! The African Queen.
African Queen: Everything works as advertised...About the boat...It has seen better days...
The African Queen was not Bogart's best work. My favorite was The Maltese Falcon, which didn't get best picture, but should have. Casablanca was another one far better than African Queen. Both benefited from having Peter Lorre and Sydney Greenstreet in supporting roles.
Another Good Video. TQ___African Queen
Thank you! 🤗
Why is the camera not working
My Logi camera takes around 30 sec to come up, but works fine "AFERICAN QUEEN"
Now, now... my fav as of late is iced tea. No sweetener, no lemon. I used to be a coffee drinker, but couldn't stomach it when it got cold. Good Arabica is hard to find anymore, unless you roast and grind your own. That carburetor cleaner they sell at places like Starbucks is disgusting.
I am using a laptop with a webcam. My code runs perfectly using python3.6.8.