title
Training Haar cascade object detection - OpenCV with Python for Image and Video Analysis 20

description
In this tutorial, we cover how to train the Haar Cascade classifier, using our positive and negative images. This is used with OpenCV for general object detection and recognition. Text-based tutorial and sample code: https://pythonprogramming.net/haar-cascade-object-detection-python-opencv-tutorial/ Digital Ocean Server: https://www.digitalocean.com/?refcode=d1c4c6e66979 https://pythonprogramming.net https://twitter.com/sentdex https://www.facebook.com/pythonprogramming.net/ https://plus.google.com/+sentdex

detail
{'title': 'Training Haar cascade object detection - OpenCV with Python for Image and Video Analysis 20', 'heatmap': [{'end': 271.734, 'start': 236.998, 'weight': 0.72}, {'end': 405.938, 'start': 387.765, 'weight': 1}], 'summary': 'Tutorial explains the process of creating a hard cascade file for object detection using opencv with python, covering training steps, positive images creation, and optimizing server performance for ram cache management and digital ocean server management.', 'chapters': [{'end': 156.713, 'segs': [{'end': 32.116, 'src': 'embed', 'start': 2.964, 'weight': 0, 'content': [{'end': 7.046, 'text': "What's going on, everybody? Welcome to another OpenCV with Python tutorial.", 'start': 2.964, 'duration': 4.082}, {'end': 15.209, 'text': "In this video, we'll hopefully be wrapping up the creation of our own hard cascade file for object detection of really any object.", 'start': 7.086, 'duration': 8.123}, {'end': 16.41, 'text': "That's the whole idea here.", 'start': 15.249, 'duration': 1.161}, {'end': 20.132, 'text': "I'm almost done uploading the data set that we just created.", 'start': 17.03, 'duration': 3.102}, {'end': 26.074, 'text': "So now I'm back into the terminal right now, and we're going to do a few things.", 'start': 21.252, 'duration': 4.822}, {'end': 28.715, 'text': 'So first of all, I just re-logged back in.', 'start': 26.174, 'duration': 2.541}, {'end': 32.116, 'text': "So I'm going to change directory into that workspace that we created.", 'start': 28.755, 'duration': 3.361}], 'summary': 'Opencv tutorial on creating hard cascade file for object detection, almost done uploading the data set.', 'duration': 29.152, 'max_score': 2.964, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo2964.jpg'}, {'end': 108.872, 'src': 'embed', 'start': 64.866, 'weight': 1, 'content': [{'end': 71.371, 'text': "I mean just take a picture of anything, convert it to a 50-50, and train using the three commands we're about to run,", 'start': 64.866, 'duration': 6.505}, {'end': 77.095, 'text': 'because these negative images are good for anything basically besides people, okay?', 'start': 71.371, 'duration': 5.724}, {'end': 79.997, 'text': 'So you can train to track really anything you want.', 'start': 77.435, 'duration': 2.562}, {'end': 81.64, 'text': 'Okay, it says the transfer is done.', 'start': 80.379, 'duration': 1.261}, {'end': 83.54, 'text': 'Let me make sure I have everything I need.', 'start': 81.68, 'duration': 1.86}, {'end': 91.104, 'text': 'Right, bg.txt, neg, OpenCV, which we installed a long time ago, and the watch 50 by 50.', 'start': 84.421, 'duration': 6.683}, {'end': 94.385, 'text': "So now what we want to do is let's go ahead and make dir.", 'start': 91.104, 'duration': 3.281}, {'end': 95.166, 'text': 'We need two dirs.', 'start': 94.425, 'duration': 0.741}, {'end': 98.047, 'text': "We're going to make dir data.", 'start': 95.186, 'duration': 2.861}, {'end': 102.169, 'text': 'This is where our cascade information is going to go later on.', 'start': 99.448, 'duration': 2.721}, {'end': 105.69, 'text': "And then we're also going to make dir info.", 'start': 102.529, 'duration': 3.161}, {'end': 108.872, 'text': 'This is where the positive images are about to go.', 'start': 105.991, 'duration': 2.881}], 'summary': 'Train model to recognize objects using 50x50 images and two directories.', 'duration': 44.006, 'max_score': 64.866, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo64866.jpg'}], 'start': 2.964, 'title': 'Creating object detection cascade', 'summary': 'Details the process of creating a hard cascade file for object detection using opencv with python, emphasizing the steps for training using negative and positive images and the command for creating samples.', 'chapters': [{'end': 156.713, 'start': 2.964, 'title': 'Creating object detection cascade', 'summary': 'Details the process of creating a hard cascade file for object detection using opencv with python, emphasizing the steps for training using negative and positive images and the command for creating samples.', 'duration': 153.749, 'highlights': ['The tutorial covers the process of creating a hard cascade file for object detection using OpenCV with Python, including the steps for training using negative and positive images, and the command for creating samples.', 'The tutorial emphasizes the importance of using an image of interest for training, and highlights that negative images can be used for tracking any object other than people.', 'The tutorial explains the commands for creating directories for cascade information and positive images, and demonstrates the command for creating samples using OpenCV.']}], 'duration': 153.749, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo2964.jpg', 'highlights': ['The tutorial covers the process of creating a hard cascade file for object detection using OpenCV with Python, including the steps for training using negative and positive images, and the command for creating samples.', 'The tutorial emphasizes the importance of using an image of interest for training, and highlights that negative images can be used for tracking any object other than people.', 'The tutorial explains the commands for creating directories for cascade information and positive images, and demonstrates the command for creating samples using OpenCV.']}, {'end': 792.617, 'segs': [{'end': 277.437, 'src': 'heatmap', 'start': 236.998, 'weight': 0, 'content': [{'end': 240.419, 'text': "so we have, yeah, we've got 1964 total.", 'start': 236.998, 'duration': 3.421}, {'end': 241.36, 'text': "so we'll use 1950.", 'start': 240.419, 'duration': 0.941}, {'end': 249.104, 'text': "i think that'll be good enough, and then we'll actually end up using even less, and i'll explain why when we get there.", 'start': 241.36, 'duration': 7.744}, {'end': 252.305, 'text': 'so, um, this will create 1950 positive images.', 'start': 249.104, 'duration': 3.201}, {'end': 257.947, 'text': "so go ahead and hit enter, creating samples, and it's done it.", 'start': 252.305, 'duration': 5.642}, {'end': 258.748, 'text': 'does it that fast?', 'start': 257.947, 'duration': 0.801}, {'end': 259.789, 'text': "it's crazy.", 'start': 258.748, 'duration': 1.041}, {'end': 262.29, 'text': 'so let me go over to win scp here.', 'start': 259.789, 'duration': 2.501}, {'end': 264.451, 'text': "let's update this all right.", 'start': 262.29, 'duration': 2.161}, {'end': 267.892, 'text': 'and let me pull up our, just our working directory.', 'start': 264.451, 'duration': 3.441}, {'end': 271.734, 'text': "and so we go into info and it'll take a second to load all these images.", 'start': 267.892, 'duration': 3.842}, {'end': 273.175, 'text': 'but here are all the images.', 'start': 271.734, 'duration': 1.441}, {'end': 277.437, 'text': "and then this is like our bg.txt, only it's, uh, made for this.", 'start': 273.175, 'duration': 4.262}], 'summary': 'The process generated 1950 positive images, with a total of 1964 initially available.', 'duration': 40.439, 'max_score': 236.998, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo236998.jpg'}, {'end': 410.12, 'src': 'heatmap', 'start': 387.765, 'weight': 1, 'content': [{'end': 395.453, 'text': "And then where do we want the vec file to be saved to? We'll just save it in this directory as positives.vec.", 'start': 387.765, 'duration': 7.688}, {'end': 405.938, 'text': 'Save that and we do 20 by 20, because The the larger you make these images, like 20 by 20,', 'start': 396.551, 'duration': 9.387}, {'end': 410.12, 'text': 'is like kind of the average that people will recommend you use kind of.', 'start': 405.938, 'duration': 4.182}], 'summary': 'Save vec file as positives.vec in current directory, use 20x20 images.', 'duration': 22.355, 'max_score': 387.765, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo387765.jpg'}, {'end': 471.553, 'src': 'embed', 'start': 445.156, 'weight': 3, 'content': [{'end': 449.778, 'text': "you can make this larger and you will actually detect the full size of whatever you're looking for.", 'start': 445.156, 'duration': 4.622}, {'end': 451.139, 'text': "but you don't have to.", 'start': 449.778, 'duration': 1.361}, {'end': 457.721, 'text': 'you will still find it with these, because the way a hard cascade works, it breaks down very small features.', 'start': 451.139, 'duration': 6.582}, {'end': 460.042, 'text': "basically, if you saw, it's almost like a zero and one.", 'start': 457.721, 'duration': 2.321}, {'end': 468.026, 'text': "it's very binary types of features, so the size doesn't matter as much, it just simply doesn't so.", 'start': 460.042, 'duration': 7.984}, {'end': 471.553, 'text': 'Anyway, that was our vector file.', 'start': 469.873, 'duration': 1.68}], 'summary': 'A vector file can detect full size without needing to be enlarged due to the binary features of hard cascade.', 'duration': 26.397, 'max_score': 445.156, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo445156.jpg'}, {'end': 619.012, 'src': 'embed', 'start': 587.237, 'weight': 4, 'content': [{'end': 590.578, 'text': 'Use, you know, leave a nice few hundred leeway there.', 'start': 587.237, 'duration': 3.341}, {'end': 596.099, 'text': "Num stages, the more stages you use, the more accurate-ish it's going to be.", 'start': 591.238, 'duration': 4.861}, {'end': 599.7, 'text': 'But the more stages you use, the much longer it will take to train.', 'start': 596.739, 'duration': 2.961}, {'end': 603.782, 'text': 'Like stage one or stage 0, will be pretty quick.', 'start': 599.74, 'duration': 4.042}, {'end': 608.085, 'text': 'stage 1 will be a little slower, stage 10 will be even a little more slower than that one.', 'start': 603.782, 'duration': 4.303}, {'end': 612.328, 'text': 'and as you go on, getting through stage 10 is like 10 times as slow as getting through stage 1.', 'start': 608.085, 'duration': 4.243}, {'end': 613.568, 'text': "it's very slow.", 'start': 612.328, 'duration': 1.24}, {'end': 619.012, 'text': "so this process, even though 10 stages, it'll probably take two to four hours.", 'start': 613.568, 'duration': 5.444}], 'summary': 'Using 10 stages will take 2-4 hours, increasing in slowness', 'duration': 31.775, 'max_score': 587.237, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo587237.jpg'}, {'end': 727.778, 'src': 'embed', 'start': 704.239, 'weight': 2, 'content': [{'end': 711.266, 'text': "Let's say you train to 10 stages and you output a cascade that was created from 10 stages, and later on you want to train to 20.", 'start': 704.239, 'duration': 7.027}, {'end': 715.049, 'text': 'What you can do is you can run the same command so long as all the other parameters are the same.', 'start': 711.266, 'duration': 3.783}, {'end': 725.116, 'text': "You'll have the data that leads up to stage 10 and you can begin training at stage 10 so long again as all the other parameters are identical.", 'start': 715.669, 'duration': 9.447}, {'end': 727.778, 'text': 'So for example, this is zero stage.', 'start': 725.737, 'duration': 2.041}], 'summary': 'Cascade training allows incremental learning with minimal parameter changes.', 'duration': 23.539, 'max_score': 704.239, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo704239.jpg'}, {'end': 802.69, 'src': 'embed', 'start': 773.604, 'weight': 5, 'content': [{'end': 777.108, 'text': 'Just control C, hit the up arrow and use nohup.', 'start': 773.604, 'duration': 3.504}, {'end': 783.814, 'text': "And what nohup is gonna do is it runs the command in the background and you can leave your session and it'll still continue running.", 'start': 777.488, 'duration': 6.326}, {'end': 789.696, 'text': "Normally, like if this was running and you closed out of your terminal, it's gonna log your user out and the command won't run.", 'start': 784.314, 'duration': 5.382}, {'end': 792.617, 'text': "But if you use nohub, it'll run just in the background.", 'start': 789.756, 'duration': 2.861}, {'end': 794.298, 'text': "So, and that's what it's doing here.", 'start': 792.858, 'duration': 1.44}, {'end': 798.84, 'text': 'And we can come back over here and just make sure it is indeed running, which it is.', 'start': 794.798, 'duration': 4.042}, {'end': 802.69, 'text': 'Okay So go ahead and let that run.', 'start': 799.501, 'duration': 3.189}], 'summary': 'Using nohup allows running commands in the background, ensuring they continue even after session closure.', 'duration': 29.086, 'max_score': 773.604, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo773604.jpg'}], 'start': 156.713, 'title': 'Image and cascade training', 'summary': 'Covers the creation of 1950 positive images and vector files for object detection, along with the training process using opencv, including parameters and impact on training time and memory usage.', 'chapters': [{'end': 405.938, 'start': 156.713, 'title': 'Creating positive images and vector files', 'summary': 'Discusses the process of creating 1950 positive images for object detection, including the generation of background information, image info, and vector files, as well as the parameters and commands used for the creation process.', 'duration': 249.225, 'highlights': ['The process involves creating 1950 positive images for object detection. The speaker explains the need to create 1950 positive images and mentions that they actually have 1964 total images, deciding to use 1950 for the process.', 'Description of the image info file format and content. The speaker describes the content of the image info file, including the image path, number of objects, and their locations, emphasizing the consistency of width and height in the images.', 'Explanation of the parameters and commands used for creating the vector file. The speaker details the parameters used for creating the vector file, including the total number of images, width, and height, and specifies the destination for saving the vec file.']}, {'end': 792.617, 'start': 405.938, 'title': 'Training cascade for object detection', 'summary': 'Discusses the process of training a cascade for object detection using opencv, specifying the parameters, and the impact on training time and memory usage.', 'duration': 386.679, 'highlights': ['The training process is impacted by the size of the cascade, with larger sizes leading to longer training times. The larger the cascade, the longer it takes to run the training process.', 'The detection quality of the cascade is affected by its size, with larger sizes allowing for detection of the full size of the object being looked for. Larger cascade sizes enable detection of the full size of the object being sought.', 'The impact of stages on training time, with more stages leading to slower training. More stages in training lead to a slower training process, with each subsequent stage taking longer.', "The use of 'nohup' command to run the training process in the background, enabling continued execution even after closing the terminal. The 'nohup' command allows the training process to run in the background, ensuring continued execution even after the terminal is closed."]}], 'duration': 635.904, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo156713.jpg', 'highlights': ['The process involves creating 1950 positive images for object detection.', 'The speaker explains the need to create 1950 positive images and mentions that they actually have 1964 total images, deciding to use 1950 for the process.', 'The training process is impacted by the size of the cascade, with larger sizes leading to longer training times.', 'The detection quality of the cascade is affected by its size, with larger sizes allowing for detection of the full size of the object being looked for.', 'The impact of stages on training time, with more stages leading to slower training.', "The use of 'nohup' command to run the training process in the background, enabling continued execution even after closing the terminal."]}, {'end': 1079.649, 'segs': [{'end': 963.136, 'src': 'embed', 'start': 930.414, 'weight': 2, 'content': [{'end': 931.675, 'text': 'I have to get install Htop.', 'start': 930.414, 'duration': 1.261}, {'end': 935.437, 'text': 'It should be pretty quick.', 'start': 934.716, 'duration': 0.721}, {'end': 937.018, 'text': 'Yep Bring that up.', 'start': 935.477, 'duration': 1.541}, {'end': 940.22, 'text': 'And then now we can see how are our CPUs doing good.', 'start': 937.258, 'duration': 2.962}, {'end': 941.941, 'text': "We've got memory usage.", 'start': 940.68, 'duration': 1.261}, {'end': 943.021, 'text': "We're actually at a pretty good.", 'start': 941.981, 'duration': 1.04}, {'end': 944.182, 'text': 'We actually have quite a few free.', 'start': 943.041, 'duration': 1.141}, {'end': 945.743, 'text': 'We had a huge cache though.', 'start': 944.202, 'duration': 1.541}, {'end': 949.906, 'text': "So that cache, as it runs up, you'll max this out.", 'start': 946.183, 'duration': 3.723}, {'end': 958.713, 'text': "And if you have no swap left, uh, your digital ocean server will reset, and so that's no good.", 'start': 949.926, 'duration': 8.787}, {'end': 963.136, 'text': 'so um so, you just leave it like this and you should be good.', 'start': 958.713, 'duration': 4.423}], 'summary': 'Installing htop to monitor cpu and memory usage, ensuring server stability.', 'duration': 32.722, 'max_score': 930.414, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo930414.jpg'}, {'end': 1074.927, 'src': 'embed', 'start': 1039.09, 'weight': 0, 'content': [{'end': 1041.711, 'text': "And then we'll actually incorporate it and test it and see how well it worked.", 'start': 1039.09, 'duration': 2.621}, {'end': 1051.494, 'text': "So as long as you're getting output that looks like this, either here or to your nohup.out file here, you're totally fine.", 'start': 1042.192, 'duration': 9.302}, {'end': 1052.735, 'text': "Everything's running as it should.", 'start': 1051.534, 'duration': 1.201}, {'end': 1055.556, 'text': "And if you use nohup, you can log out and you're totally fine.", 'start': 1052.935, 'duration': 2.621}, {'end': 1063.823, 'text': "Just remember to set up the cron tab to clear caches, because otherwise you're going to run out most likely of memory, even though it'll be cached.", 'start': 1055.596, 'duration': 8.227}, {'end': 1070.486, 'text': "you'll be, it'll be all stuffed up, and then the server will shut down, will restart and then it won't restart your command.", 'start': 1063.823, 'duration': 6.663}, {'end': 1074.927, 'text': 'so anyways, uh, questions, comments, leave them below.', 'start': 1070.486, 'duration': 4.441}], 'summary': 'Testing incorporation success, use nohup for stable running, set up cron tab for clearing caches to avoid memory issues.', 'duration': 35.837, 'max_score': 1039.09, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo1039089.jpg'}], 'start': 792.858, 'title': 'Server performance optimization and management', 'summary': 'Covers optimizing server performance through ram cache management, such as clearing cache every minute, monitoring cpu and memory usage, and preventing ram overload. it also discusses managing digital ocean server for long processes, highlighting the need for managing swap space, clearing caches to avoid resets, and emphasizing the importance of monitoring output and incorporating completed files for testing.', 'chapters': [{'end': 949.906, 'start': 792.858, 'title': 'Optimizing server performance with ram cache management', 'summary': 'Discusses optimizing server performance by managing ram cache, including running a script to clear cache every minute, monitoring cpu and memory usage, and preventing ram overload to maintain system stability.', 'duration': 157.048, 'highlights': ["Running a script to clear RAM cache every minute using 'cron tab' and 'echo' command to prevent system overload and maintain stability.", "Monitoring server performance with 'Htop' to track CPU and memory usage, ensuring adequate free memory and managing cache buildup.", 'Emphasizing the importance of managing RAM cache to prevent system instability and potential RAM overload issues leading to server disruptions.']}, {'end': 1079.649, 'start': 949.926, 'title': 'Managing digital ocean server and running long processes', 'summary': 'Discusses running a long process on a digital ocean server, emphasizing the need for managing swap space and clearing caches to avoid server resets and shutdowns, and highlights the importance of monitoring output and incorporating the completed file for further testing.', 'duration': 129.723, 'highlights': ['Managing swap space and clearing caches is crucial to avoid server resets and shutdowns, ensuring smooth process execution and completion.', 'Monitoring output and incorporating the completed file are important for testing the process and ensuring its effectiveness.', 'Emphasizing the need to set up the cron tab to clear caches in order to prevent memory issues, server shutdowns, and command restart failures.']}], 'duration': 286.791, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eay7CgPlCyo/pics/eay7CgPlCyo792858.jpg', 'highlights': ["Running a script to clear RAM cache every minute using 'cron tab' and 'echo' command to prevent system overload and maintain stability.", 'Emphasizing the need to set up the cron tab to clear caches in order to prevent memory issues, server shutdowns, and command restart failures.', "Monitoring server performance with 'Htop' to track CPU and memory usage, ensuring adequate free memory and managing cache buildup.", 'Managing swap space and clearing caches is crucial to avoid server resets and shutdowns, ensuring smooth process execution and completion.', 'Emphasizing the importance of managing RAM cache to prevent system instability and potential RAM overload issues leading to server disruptions.', 'Monitoring output and incorporating the completed file are important for testing the process and ensuring its effectiveness.']}], 'highlights': ['The tutorial covers the process of creating a hard cascade file for object detection using OpenCV with Python, including the steps for training using negative and positive images, and the command for creating samples.', 'The process involves creating 1950 positive images for object detection.', "Running a script to clear RAM cache every minute using 'cron tab' and 'echo' command to prevent system overload and maintain stability."]}