Object rotation using Darknet, YOLO, and OpenCV

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I want to be able to rotate an image so that it always faces the same way up and that's what I've got happening here so here are the results let me get the other windows position so that we can see a bit more this top left shows the original frame that I'm reading from a webcam this second window is the dark net YOLO output the window at the bottom here just shows a bunch of debug information and the window on the right is the result this is running in my VM so dark net YOLO is running using CPU only not GPU and on top of it the webcam access through the VM is kind of slow but no matter how I turn the playing card you can see the window on the right side the card will always be upright so it is rotated however way it needs to be wrote rotated to show up the same way there's other ways of doing this in opencv for example with the nice slot background that I've got you could easily get the Contour and from the Contour you can figure out the angle but in real world images you don't normally have such nice even backgrounds you might get a lot of texture or there might be other objects in play in which case if you're already using object detection like you're using darknet YOLO to find things in your image then it's trivial to say well at the same time that we're finding these things why don't we also find some corners or find some particular Edge or find some kind of landmark in the image that you can use to figure out which way it's aiming so that you can apply some rotations and the rotation that I use is very typical opencv technique let me quickly jump to that I'm going to show you the source code there's you know 116 lines of code here of which maybe 20 are relevant to figuring out the angle and then rotating the image first thing we do is we load the neural network set a bunch of parameters we open up the webcam here and then we begin a while loop we read in the frame this line here is where we call the neural network to get it to do all of the fancy things the dark net YOLO does it's just that one line and then we take all of the predictions that came out of darknet YOLO we take the the coordinates of all of the corner rectangles and we insert them in a opencv contour and you'll see why here in this line here we take that contour and we tell opencv tell me what the rotated rectangle is for all of these points in the Contour then at that point it's just a matter of uh figuring out exactly um what the rotation angle needs to be we create the rotation Matrix here and this is where we rotate the image after that we just we show the four images that we have and we wait for the user to press a key so like I said there are easier ways of doing it except if you don't have a nice uniform background to work with in which case this is probably the easiest way to do it hope this helps come join us on the dark net YOLO Discord if you have any questions or suggestions thanks
Info
Channel: Stephane Charette
Views: 6,048
Rating: undefined out of 5
Keywords: darknet, yolo, neural network, opencv, c++, linux, image rotation, darkhelp, object detection, computer vision
Id: eFsljRvPHp0
Channel Id: undefined
Length: 4min 12sec (252 seconds)
Published: Fri Oct 28 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.