OpenCV & MoviePy - Analyzing video frames - python

I've been using OpenCV and MoviePy to get images out of a video (1 image per second) and once extracted, I analyze the image with pytesseract. The part where the script extract images takes quite a bit of time. Is it possible or is there a function that I've overlooked in MoviePy or OpenCV that allows video frames to be analyzed without having to create images first? This could tremendously speed up the process.
Current steps:
Scan and extract 1fps with a specific video as argument
From each of those images, perform analysis on a specific area
Desired:
Perform analysis on a specific area of the video itself at 1 fps.
If this function exists, please inform me. Otherwise, would there be a workaround for this? Suggestions?
Thanks!!

Related

Best image format for face detection and face recognition with the DeepFace library

I'm using the DeepFace library for face recognition and detection.
I was wondering if there is a better format (png, jpg, etc) than others to get better results.
Is there a preferred image format for face recognition and face detection generally? and specifically in this library?
Deepface is wrapped around several face recognition frameworks so the answer to your question should be: it is case-depending issue. However, all basic FR fameworks are not working with the original inpit images, they converting them first to greyscale, downsizing, making numpy arrays and so on usually using OpenCV and PIL for that. So... So, my oppinion is that image file format does not matter. Image file size, colour depth do matter.
This answer is based on an answer from 'Bhargav'.
In python, images are processed as bit bitmaps using the color depth of the graphic system. Converting a PNG image to a bitmap is really fast (20 x times) when compared to jpegs.
In my case, I had the image and needed to save it before proceeding, so I saved it as png so I won't lose quality (jpg is lossy).
Deepace - Currently accepting only 2 types of image input formats. PNG/Jpeg. there is no way to use other formats of images directly as you are using their libraries. If you want to use another input formats so then at least you need to convert either to PNG or Jpeg to give input to the functions. Which may cost you extra execution time while bringing other format images to PNG/Jpegs.
If you want to improve face recognition and face detection with deepface library then use some preprocessing filters.
Some of the filters you can try for better results. ultimate guide
Grayscale conversions
Face straightening
Face cropping (#Deepcae automatically do this while processing so no need to this)
Image resizing
Normalization
Image enhancement with PIL like sharpening.
image equalization.
Some basic filtering will be done by deepface. If your results are not accurate, which means filtering done by deepface is not sufficient, you have to try each and every filter. Something like a trail and error method until you got good results.
sharpening and grayscaling are the first methods to try.

How to take still images in python? (Other than opencv CaptureVideo)

I would like to take pictures using the USB webcam. When I use the VideoCapture method of OpenCV, it actually gives frames from the video. In most cases, still images cover more area than the video. Therefore, I am looking for a way to take pictures using the webcam which cover more of the available camera FOV.

I need help combining image and audio clips into 1 video

My goal is to make a video of a text to speech Reading images i made.
I have the images and audio as files, my goal is to combine them as a slideshow fashion where the image durations last as long as the text to speech audio duration. Also would be nice to have a transition mp4 between the clips.
The problem is that I have no idea where to start. The pymovie documentations don't seem to cover this from my understanding.
I need directions on where to go/what to use/how to use.
I am also creating the images in a for loop and planning to make a function to add the image and audio into the file
I have searched for 10-20 minutes now and didn't find anything to help me.
Keep in mind i am a newbie python programmer.

Sampling video and making image cutoffs in python

I've got a videostream (for now I just use a video). I need to get a one frame per every second or more seconds and I need to cut some part of these pictures based on 8 coordinates(leftupper x/y, rightupper x/y, rightlower x/y and leftlower x/y).
I thinkg that I'm able to do that cutting in java but I would rather do it in python as entire application is written in python / django.
It's possible to do both of that things directly in python?
Could you point me to some documentation or whatever?
You can start with some Video Handling in Python Using OpenCV
Python : Reading Video File and Saving Video File using OpenCV
It contains all the basic links like Reading from File and Camera , that gives a initial idea of how to process Frames .
Then after you get Each Frame in OpenCV mat , you can form a Bounding Box Rect to extract the Region or ROI from that
Close to this Question
Cropping Live Video Feed
Cropping a Single Frame can be done as done in
Cropping a Single Image in OpenCV Python
This can be repeated for every Frame and you can even Write to a Video File taking reference from First Reference.

Analyze a video, look for a colored pixel or logo

I want to sift through a collection of video files looking for a certain logo, and then record the 10-15 seconds leading up to it. I can recognize the logo by checking a certain pixel color.
How would you do it? Is there software or a python package that allows me to extract those chunks of files and write those into a new video?
What i have done so far:
I have found a library that is able to convert a video into a series of BMPs. What the programs. Its called pyMedia: http://pymedia.org/tut/src/dump_video.py.html and the reverse: http://pymedia.org/tut/src/make_video.py.html
So thats pretty neat. However its only working with python 2.3, not with python 3.
Seems like :
d= e.encode( yuvFrame )
fw.write( d )
writes a BMP file. So how do i look in for a certain colored pixel or logo in a BMP file and put it together? Thats what i cant get working somehow. Maybe someone can help me with this.
edit:
let me show you what i have done so far:
from PIL import Image
im = Image.open("bride.bmp")
i=0
width= 10
height = 10
top= 461
box = (left, top, left+width, top+height)
croppy=im.crop(box)
if (mycolor in croppy.getcolors()):
print "Logo found"
My logo has a certain color, so this looks for the pixel and prints logo found if the pixelcolor is found. Didnt really want to make a classifier for that.
Using perhaps OpenCV or another package -- essentially, you want to train a classifier to identify your logo and then feed it the bitmaps from your video. When it identifies the logo, then you trigger the code which captures the previous 15s of video.
This is a very detailed answer about how one might do this in Python General approach to developing an image classification algorithm for Dilbert cartoons

Categories