convert python to exe | convert py to exe | yolov8 object detection setup.exe

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello friends and welcome to YouTube channel freedomtech and in this session what we are going to learn in this session we are going to create yellow V8 object detection application with the help of tick enter and then we are going to convert our python script in setup.exe file so for that we are going to use a pi installer so this is what we are going to learn in today's session so before we move to our practical friends if you learn something from our videos please consider to subscribe our Channel okay friends thank you so much and let's get started so friends as I mentioned we are going to create here a tick inter application means I have already created The Tick inter application and it is really simple application there is nothing fancy and I have shared the full code of the application and we are going to detect the object with the help of our tick enter application where we have YOLO V8 ultralytics object detection and then we are going to use a pi installer for converting our application in setup.exe file so it means uh now you can simply install that setup.exe file and you can run your application on Windows computer so let's get started so for that first I have created a repository tick inter yellow V8 app I will mention the link inside description box you need to Simply copy and paste the link inside the browser then go to the code and click on download zip and it will download our ZIP format repository so as I mentioned inside that repository I have already create a tick inter application as you can see my app.py so my app.py is basically our full TIG enter application for yellow V8 object detection so let me open file manager downloads and this is what our repository right click WinRAR extract with the folder name so we have now our folder that's it again same folder and now first we need a packages so I have created here a packages dot txt file as you can see and this is the packages which we want for today's project so simply we want to install these packages with the help of Sony also with the help of CMD because we are going to cross check our application or we can say we are going to cross check our python script from CMD because when you install the application when we convert our application in setup.exe file and you simply try to install this application in other computer on that computer there is no Tony python ID there is nothing so the application will basically use the command prompt so we want to cross check our application in CMD where we are going to create our application on that computer so we want to install all these packages along with the Tony python ID also also from CMD our Command Prompt so let's just open our Sony python IDE and go to the tools and first package which is opencv hyphen python so let's just search for opencv iPhone python opencv hyphen python hit enter opencv hyphen python click on install it will install opencv package then we need our yellow V8 means Ultra latex package so ultralytics Ultra ultralytics package hit enter first package ultralytics and it will install ultralytics just click on install button and it will install ultralytics package then we need a pi Wing 32 package so just search for Pi wheel 32 hit enter and then as you can see a pi win32 python for window extensions so simply click on 5 in 32 click on install and it will install Pi Vin 32 package on our machine the Windows machine this is Windows 11 then we need a pillow packet so just search for pillow hit enter pillow first package python Imaging Library so just click on pillow click on install button and it will install a pillow package on our Windows machine then we need CV Zone and one more package which we need so I forget to mention which is our main package which is pi installed so Pi installer Pi pip install by install by install this is whatever package so no problem I will add the package so CV Zone manage packages then again CV Zone click on enter button and series on package install it that's it it will install C Vision CV Zone package then we need Pi installer search for pi installer first package Pi installer as you can see I have already installed so just click on install or or there is if there is upgrade button simply click on upgrade button it will upgrade the packages so this is how we would need to install all these packages which I have mentioned so now same packages we want to install with our Command Prompt so just go and open the command prop so peep install opencv hyphen python then we need a ultralytics ultralytics ultralytics package then we need pillow package below and then we need CV Zone package then we need Pi win 32 package and then we need a pi installer package file installer package and uh and what else ah opencv hyphen python is there Alternatives is there uh Pi with 32 is there pillow is there and Pi installer is there and CV zone is there so uh this is the packages which we need so just install with CMD click on enter button and as you can see because I have already installed all these packages opencv hyphen python ultralytics for yellow V8 pillow package CV Zone package 5 in 32 and the pi installer this is the packages which we need for today's project that's it so we have done with package installation now simply I have created the my app dot Pi so just open the my app dot pi and this is whatever code so this is the uh packages which we import win 32 event to win 32 API import CS from win error input error already exists uh this is the this is the code if suppose we create our setup.exe file and if there is something error or you can say if the application takes some time so it will it will check if there is error or not so it will take care of all this win32 error process so for that we have to mention this code first then our main model which is Tick enter Then c v two then pil is basically a pillow from pillow pil we are going to import image image TK then tick enter file dialog because we are going to create here the option where user can upload their video file also and with the help of video file also we are going to detect a object so for that we need a file dialog option from tick enter then we have our pandas as a PD because we are going to use our yellow V at object detection method so if you follow my old video then you definitely know we use pandas for uh pandas for the data the data from our our yellow V8 so for that we need a pandas we are going to convert our yellowware data in table format so for that we need appenders then ultralatics import yellow this is what our main package then CV Zone and the threading that's it so simple ah if we want to create our application so we want to Simply uh first mention some Global variables cap is equal to also none is camera also false then we are going to skip here some frames because right now I am working on CPU there is no GPU so we are going to skip some frames so basically we are going to skip three frames so it will it will uh it will work fast it will work fast so frame count is equal to 0 then frames keep threshold three you can simply change here frame rate as per your requirement then this is the model yellow yellow V8 s dot PT this is the pre-trained by default model and the video Power Pause is basically the force so this is the global variables which we want to declare first then ah then we have our coco.txt file if you open the repository so inside that as you can see this is what our Poco dot txt file and inside that coco.txt file we have all our classes we have all our classes so ah here also we are going to mention the option menu suppose if user want to detect only one class let's say if I just want to detect here a person from video or from the web camera so we we mention here a selection option menu uh drop down menu where we have all these all these classes and user can simply select a one class from this list so for that we want to read our coco.txt file so for that I have create here uh read classes from file this is the this is the function so how we read our normal txt file so this is the simple things file path is basically the object with open file path then the we have we are going to only read the file so for that r as a file then classes is equal to we are going to use here line dot strip method and we have because our classes is line by line so we want to read each line so line dot strip method for line in our file and then we are going to return our classes simple then depth staff webcam this is the start webcam function where Global cap is camera on is also Global variable because we mention it here as you can see clap is camera on so cap is also Global variable each camera on is also Global variable also video pause is also the Global variable so first what we want to mention here we want to mention our if condition if not is camera on then cap is equal to C2 dot video capture and we want to mention our index number the camera index number then is camera on is equal to true video pause is equal to false why because now we want to start our web camera so of course we want to mention video pause the global variable false and then update canvas is next function where we are going to update our frame so this is the start webcam function simple function simple method then same way stop webcam again Global cap is camera on video pass this is the global variable and here also we want to mention if cap is not none then cap dot release because right now we want to stop our web camera so if cap is not none cap dot release is camera on is false because now we want to make our camera off so each camera on is the global variable we want to mention a false also right now we don't want to make our video pause we want to completely shut our camera so video pause is also false then this is the pause and resume video so Global video pause video pause not video pause video pause means first it will pause our video and same button will release or we can say the resume video simple so pause resume video function then select file this is the this is the function for user to select their file so go Global cap is camera on video pause this is our Global variable if the camera is on stop webcam because right now user want to upload their video file the user don't want to use their web camera so for that if the camera is on stop the webcam function so for that we mentioned stop webcam then file path is just a variable now we want to use here from thick enter file dialog we want to use your our file dialog so here it is as you can see I have mentioned the file dialog from file dialog dot ask open file name and file types video files and we are going to allow this MP4 Avi and mov format you can add format as per your requirement so MP4 Avi and mov format then simple if there is file path means now user select their uh the video file and simply want to create no condition so if the if the user select their video file so if the file path is there simply we want to mention cap is equal to C2 dot video capture and inside that we want to pass our file path variable because file part is our video file so file path then is camera on is true then video pass is basically false and update canvas we want to Simply update our canvas because now we want to update our frame we want to update our frame with the help of our video file simple so Dev update canvas this is the main function where we are going to work with our frame either it is a video file or whether it is a live webcam field so same variable Global variable so if the camera is on if not video pause red frame is equal to cap dot read and if there is red of course we are going as I mentioned we are going to skip here some frame so the frames we are going to skip as we mentioned three if you have a GPU a powerful GPU there is no need to skip the frame because right now I am working on CPU machine so I need to skip the frames for better performance so this is the method where we are going to skip our frames then canvas dot after 10 after 10 milliseconds we are going to call our update canvas function so here it is as you can see I have mentioned CV2 dot color because we want to convert our frame with BGR to RGB format because openc work with BGR to RGB so simply frame CV2 dot resize now then we are going to resize our frame with one zero two zero width and five double zero is the height then selected class as I mentioned we are going to use here a class selection method for that simply selected class is equal to class selection dot get then result model dot predict this is the basic method as you can see this is the basic method this is how we call our object detection the result then the uh the PD dot data frame then we have a x one y One X two y two this is the method which I have explained in previous video several times so this is what our basic yellow V8 object detection method so where we re where we resize our frame after that we want to call our object detection frame and then of course we are going to show our frame on tick inter canvas so we want to convert our frame in Array format for that we have our pillow function which is image TK which basically convert our frame into photo image so here we have done with our object detection method now we want to convert our frame in photo image so photo is equal to image TK so image TK is from our pillow here it is as you can see from pil means the pillow input image and import image TK so image ticket which we are going to use for converting our frame in a frame in basically photo image for showing our live frame on canvas tick inter canvas simple simple fundamentals friends there is nothing ah hardcore code here simple fundamentals and here it is as you can see I have mentioned image.tk photo image and simply we want to convert our frame first we want to convert our frame in Array format with the help of pillow image function so image here it is as you can see I have mentioned the I is basically capital Y because we are going to use here from pil we are going to use your image so here it is as you can see the I is capital so this image is basically convert our frame in Array format for showing our frame in tick inter canvas that's it so for that image is equal to image Dot from array and inside that we want to pass our this Frame this Frame simple after that canvas dot IMG this photo then canvas create we want to create our image and we want to show our image this photo image on our canvas and then canvas Rod after 10 millisecond update canvas method that's it then quit we have quit button which basically quit our application so stop webcam root dot quit and root dot destroy and this is what our buttons root dot TK dot TK the title title of our application then this is this is the canvas method we are going to use your TK dot canvas root with is one zero two zero height is five double zero then canvas dot pack fill both way expand true then class list is equal to we are going to call our read classes from file function this one function the first function read classes from file which basically read our coco.txt file so we want to mention inside that file we want to mention coco.txt file and then the class selection method for that we are going to use TK dot string wire method and class selection by default it will select all the classes from our list means when users start application by default it will detect all the object for that we want to mention class selection dot set all class selection dot set all and then here it is as you can see selected class selected class is equal to this class selection this class selection as you can see this class selection we mentioned here for set this class selection and then here we want to get the selection so for that class selection dot get method first we want to set the class selection which is all then we want to call class selection dot get method for getting the request simple I am trying to explain all this code really simple reference ok so class selection set class selection set and by default as you can see default selection is basically the all you will get the idea when we start our application we will get the detail idea let me first explain the code class selection label and we want to mention the class selection this is just a label not button so it will put the label class selection inside that the text we mentioned for that label which is Select class and we are going to put the label on our main window which is root window as you can see the root window is our main window root simple and then we are going to mention the side of course we want to pack all these things so class selection label dot pack we want to pack and the side is basically left if you create the button we want to Simply mention we want to pack the button so this is the method create the label pack the label create the button pack the button this is the method for tick enter so class selection entry now we want to create a option menu for selecting the entry so class selection entry TK as you can see the option menu we are going to use from the TK and here we want to mention the root which is the main window and we want to mention the class selection this variable the class selection because this is the label so first it will paste our label then we have all then we are going to use our class list this class list is basically our coco.txt which we are going to read with the help of our line dot strip function so we want to mention this class list as you can see here with this star class list and here I have mentioned populate drop down with classes from text file it will populate all the drop down classes with the help of our class file which is coco.txt simple then of course this also now we want to pack so entry dot pack side is left and then we have SIMPLE buttons as you can see we have here buttons a play button stop button select file button as I mentioned this is the simple code file button TK dot button button frame is our main frame here it is as you can see we create how we want to put our button on the frame means how we want to show our frame the button frame so here we want to mention first the button frame and then we want to call all inside uh buttons we want to call our button frame method simple so this is the buttons which is Select file pause resume and quit that's it and then here friends when we when we use object detection method because this is heavy application so it will take some time when we click on play button it will take some time to start the object detection so meanwhile what we are going to do we are going to show some image so we have here inside repository I have mentioned a image which is basically ultralytics image the YOLO jpg as you can see this is the image so this image we are going to show meanwhile uh the process going uh on basically the backend process means if you click on the play button it will take some time to uh it will take some time to start the webcam then the object detection so meanwhile we are going to show this image we can say this is the loading image simple so for that we want to call this as a load image so initial image is basically image dot open this is the image name which we have inside our repository I have already mentioned it so no problem I have already mentioned all these things in repository there is no worry friends as you can see yolo.jpg so simply we are going to call this image you can study this code you can study this code step by step so initial image I have mentioned the image then simply image.tk photo image again we want to convert the image in photo image so initial image this one then here it is as you can see we want to create a canvas separate canvas for this particular image that's it so now this is what our basic simple tick inter application code for yellow V8 as I mentioned you can study this code and you will get the idea it is really simple and basic fundamentals so now what we are going to do simply we are going to start our application and of course this is the yellow V8 application so first it will download our yellow V8 s dot PT because inside repository there is no pre-trained model so when we start our object detection means when we start our application first it will download Yellow V8 s dot p t a pre-trained model so let's just first start our code and then as I mentioned we want to run this code with our Command Prompt also so as you can see it's now downloading our yellow V8 s dot PT pretrend model so friends as I mentioned as you can see this is what our image ultrolytics image now simply we want to click on play button and it will start our web camera so just click on play button so now camera is on but it will take some time so meanwhile as you can see there is still our image there is still our image and now as you can see it started our live detection it's detecting me as a person simple so this is what our live object detection with the help of yellow weight and tick enter application now simply if you want to stop you can simply click on stop the camera will exit now select file click on select file it will ask to select your video file so now I have here a video file which is CCTV and if I click on that file as you can see the video file is now running inside our application there is a lots of traffic there is a detection now simply I am going to pause the video so as you can see the video is pause I have click on pause and resume button so video is pause now we want to start our video again same way click on same button it will resume our video again click on pause now friends as you can see because we mention here a class selection so user can select any class so right now as you can see it's detecting all class because here the all is default now simply if you click here and here it is as you can see it's basically reading our coco.txt file so inside TXU file how many class we have we have lots of classes because we are using a print by default model so you can select all these classes so let's just see let's just say from this video I just want to detect right now person so if I click on person and if I resume the video file so as you can see now if I pause the video as you can see right now it's only detecting the person from this video file there is lots of object there is a car there is a bicycle but it's not detecting other object because we select here a person that's it now I want to detect here only the bicycle so let's just click on here click on motorcycle again resume now as you can see it's only detecting motorcycle there is a car but it's not detecting the car again simply click on pause button now simply select the car again click on pause resume now as you can see it's only detecting the car it means your application is perfectly working now I have passed my video file so simply so now if I want to start again my web camera just click on stop and then click on play button it will start your web camera so right now as you can see there is no detection because we select here car class so if I select the person there is a detection it's now detecting only the person so now again click on stop button select file button so I have here another a video file also which is let's say this one so this is basically a school bus where we have person as you can see now it's detecting the person simple so friends now again if I click on stop button if I click on play button it will start my web camera that's it so this is how a vertic inter application work now I want to quit my application so now click on stop button it will release our camera and then quit the button it will safely close your application this is our friends our tick inter simple application work now we have create our application now as I mentioned we want to cross check our application with the help of CMD because we want to create our setup.exe file and which computer where we want to run our setup.exe file in that computer there is no python there is no Tony editor nothing so there is only command prompt so we want to cross check our application if it is work perfectly work with CMD so friends simply this is what our repository inside downloads We have tick inter yellow gate app main folder and again same folder and inside that we have all our application related files so you will be at s dot p t my app Dot py and then packages.txt all these files so here we want to click here and simply mention CMD it will open the CMD with our directory as you can see now simply here it is as you can see I have closed the Sony python ID remember one thing when you want to run the code with CMD just close the Sony python ID so I have closed the Sony python ID now we are going to Simply run the python command space our script name which is my app.pi and just hit enter and it will open our application there is no error because we install our packages so our application is perfectly working with CMD also now just cross check if I click on play button it will start our webcam now click on stop button select file and I have select the file video file it's working perfect if I click on pause button it pause select file so I have select the file I want to select now class so if I select here person resume click on play button stop then select file and then if I again select a video file and then pause button so now as you can see it's only detecting the person so now let's just select a car resume and as you can see now it's detecting only car again pause if I select a motorcycle resume now as you can see it's only detecting the motorcycle so our code is perfectly working with the Tony also also the CMD now we are ready now simply click on stop button and click on quit button that's it so now we have done with application creating part now we want to convert our application in setup.exe file so for that we have our PI installer so let me close the CMD again CMD we are now inside our repository so here what we want to do we want to Simply run the command like this way by installer Pi installer because we install our PI installer package so Pi installer space hyphen hyphen before we start our PI installer let's just create a separate folder so here inside our repository just create a new folder and mention the name which is my app and copy and paste our python script which is my app.pi just copy it inside the my app.pi just copy paste it it will really good to work with creating separate folder and inside that we are going to paste our python code means when we convert our uh script in setup.exe file now it means it will save all the file sense folder for our application for our setup.exe file inside our mayaf folder cool so open the CMD as you can see I have opened the CMD and now we create a my app folder so let's just let me close the CMD and we are now inside our Maya folder here we are going to run our CMD here we are going to run our CMD now it's really you easy to use now buy installer Pi installer space we want to create all the files with one file we want to we don't want to create a multiple files for our application we want to create only one file including all the files so hyphen hyphen one file is the option then hyphen w I installer is our main command space hyphen hyphen one file space hyphen W and then we want to mention our python script name which is my app.pi that's it this is what our full command Pi installer space hyphen hyphen one file space hyphen w space our python script name which is my app.pi in my case just hit enter now the process is started it will take some time meanwhile I will pause a video so friends as you can see we have completed our process now we simply open our repository and same folder and inside that we have create our my app folder and as you can see now we have all the application related folder which is this build and we have my app dot spec text file so let's just open the text file and inside this file we want to mention some changes so what changes we want to mention for that I have mentioned in repository I have mentioned CH dot txt file so let's just open that file also so this is whatever CH dot txt file and this is whatever my app dot spec text file so simply from CH dot txc just copy the code copy as it is just copy it and open the my app text file and just remove from a to this no archive false from a to no archive is equal to false just delete it and what we copy from our c s dot txt just paste here here it is as you can see the mouse is basically here so just Control Plus V that's it and here here it is as you can see we want to mention our python script name so our python script name is basically my app dot pi so mention here my app dot Pi is already there my app dot Pi so this is whatever python script name so this is the changes you want to mention from CH dot txt file which I have already mentioned and from our application file which is my app dot spec file my app dot spec file which we have inside our Maya folder my app.speak file which is text file so inside that text file you want to copy paste the code from CS dot txt to my app.spec like this way and change the python script name with your name with your python code name so if you are using same code so you want to mention here my app.pi because in this scenario we have our my app.pi is our main python code that's it now simply click on file click on sell and just click on close it will save our file you can simply cross check just open it and as you can see we have our changes which we mentioned now again open the CMD we are now inside our Mac and again here we want to run our PI command Pi installer space and now this time we want to mention our my app dot spec file so my app dot s p e c spec file and just filter now it will mention the changes which we have mentioned inside my spec dot file so again it will take some time meanwhile I will pause the video so friends our Command runs successfully as you can see the completed successfully so we run here two commands with the pi installer so first one is basically Pi installer hyphen iPhone one file hyphen W and our python script name which basically create inside our folder which we create my app which basically create the dist folder build folder my app spec text file and inside that my app text spec file we mentioned changes with the help of our CS dot txt we copy code and we'll mention our code inside our my app.spec file and then we run the new command which is this one Pi installer space my app dot spec file and just hit enter it will again mention the changes inside our application then done now we have done close and simply open our Maya folder which we create inside our repository my app folder here it is as you can see now simply if you open this folder and inside that as you can see we have our setup.exe file that's it now we need here because we want to run our application so for that we need our coco.txt file also we need our ultralytics DOT jpg image so here it is as you can see this two file yolo.jpg and coco.txt yellow dot jpg and coco.txt just select it copy it and paste it inside my app dist folder where we have our setup.exe file just paste it that's it now go to the back and my app.spec then the build folder just delete it shift delete just delete it this one build if it's not deleted no problem okay if you go back my app and as you can see the build folder is deleted now inside the disk we have our map.exe coco.txt and YOLO jpg this is what our main files so if you want to share your application you want to share these three files means this is the coco.txt for our object detection and this is the yolo.jpg so now just for our testing purpose I am going to Simply cut and paste this folder on our desktop now as you can see there is no Tony also I am going to close this CMD now there is no Tony no CMD nothing we are going to Simply open our this folder where we have our my app.txt simply just click on now process is started it will first download our by default pre-trained model and then it will start our application so now as you can see I have click on myapp.exe so it its processing its processing and as you can see the windows CMD window is open so is basically download our pre-trained model which is yellow V8 s dot PT inside that as you can see we have yellow V8 s dot p t it means it's downloading our model pre-trained model and friends as you can see our application is open so now simply if you click on play button it will start our USB web camera so as I mentioned it will take some time so as you can see it started web camera and here is detecting all our object because we have here all so if I click on the person so now it's only detecting the person so remember one thing friends don't close application directly just click on stop button it will release our web camera then click on select file select the video file click on open and it will play the video file so here it is as you can see it's now from this video it's now only detecting the person there is other object but it's not detecting because we selected the person so if I go and if I select here a car now it's only detecting the car as you can see it's not detecting motorcycle and is only detecting the cars now if I go here and if I select the motorcycle so now it's not detecting the car it's only detecting the motorcycle so here also now I just want to stop the detection click on pause and then click on stop button and then click on quit button otherwise the process will still going in back end and the next time if you want to open the application the application will not open so now this is the process just stop it and quit stop and quit now simply if I click on again my app.exe and friends as you can see we have our application so we create a simple ticking application and with the help of Pi installer we convert our application in setup.exe file now simply if you want to share your application you want to share the dist folder and inside that this folder you have your sector.exe and all other files so I have shared the full code with the repository I hope you will learn something from this video we will meet our next video till then thank you check Karen bye
Info
Channel: FREEDOM TECH
Views: 3,912
Rating: undefined out of 5
Keywords:
Id: BZFMlmzBSNY
Channel Id: undefined
Length: 44min 26sec (2666 seconds)
Published: Wed Sep 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.