I am working on action recognition. I'm using opencv and python.
I want to extract equal number of frames (say n frames) from each video. My videos are of different lengths and I want to skip some frames in which the duration of the video is longer.
Can anyone give me an idea how to solve this?
Note that when you use imshow to display the frames of a video, you do so within a for/while loop, which is usually infinite. Setting the for/while loop to run n times will give you the first n frames of the video. In python, you can use imwrite with filename that changes with every iteration
filename = 'frame' + str(i)
imwrite(filename, img)
Related
example video
For example, I can generate a list of letters using a simple program, and record my screen to generate a video. But this cost too much time, it should be able to be done automaticallly.
Assuming that I wanna genrate a video up to 10 hours similar to the attchment, it there any quick way to do it? How to write a program which take some words (maybe about 100k words) and generate a video with small size. (The size of video should be small since the difference between two frame is small)
I want to create a basic video editing application where the user can import video clips and then use symmetry (vertical or horizontal) and offsets on their videos. How feasible is this?
For instance, consider the following image:
Right-symmetry:
Image offset to the top-left:
If that last image is confusing, basically you can think of it as the images repeating one next to the the other in a grid, infinitely, such that they're symmetric. Then, you can select a window of this grid equal to the size of the original image. Eg. the red square represents the window:
This is very feasible. Opencv can do all of this frame by frame. Although it would probably take sometime for high quality/long videos. If you want to know how to do these operations, I would open seperate questions. mirroring can for example be done by cv2.flip().
You can use the .flip () method present in the cv2 library. First enter the image with cv2.imread (path). Then to make the mirror effect you have to create a insert cv2.flip (image, 0).
Just as reported below:
image = cv2.imread(path)
mirrow = cv2.flip(image, 0)
I am working on python3 and using Microsoft azure face API function 'CF.face.detect' to detect faces in a video.
I want to detect faces after every 1 second in the video that means run CF.face.detect once/second on video frame.
Please tell how to do it
Thanks in advance
If you know how many fps your video has, you could read the frames one by one and detect on every n-th frame, n being the number of fps of a video you're processing.
fps = x
cnt = 0
for f in get_frames():
if cnt % fps == 0:
# run algorithm here
cv.imwrite(f)
After you have gone through the video then you can run the algorithm. But I would suggest to run the algorithm in the loop and save the frame then, preferably with drawn result (squares for detection)
I have a problem, not so easy to solve i guess. In general, I have a database of frames from different videos and I want to find for a given picture (which is not necessarily one of the frames but from some same source video) the matching source video.
So lets say I have some videos and extracted frames each x seconds. The frames are stored in the db.
My guess would now be to loop over all video frames in the db and try to find matching features. So I would somehow have to find features in the source image and then try to find these in the frames stored in the db.
My question is how can I achieve this? The problem is that camera angle and vieweing distance can be quite different when the picture in question was not taken quite close to the time the frame was extracted previously.
Is this even feasible?
I'm working with Python and OpenCV.
Thanks and best regards
I want to create a VideoClip of only one frame of the video. The first frame will do.I am using moviepy. I have tried writing this code:
dur=1/fps #fps= frame rate
clip=VideoFileClip("vid.mp4").subclip(0,dur)
but it did not give me any exact results in case dur was a recurring decimal.
Also I need a way to find the frame rate of an existing video.
When you create a clip with clip=VideoFileClip("vid.mp4"), the fps is given by clip.fps.
If you want to get the first frame as a clip you write
clip2 = clip.to_ImageClip(t=0).set_duration(some_duration_in_seconds)
But it is unclear what you want ot do with that first frame. Maybe if you explain more about your goal I can give you a more appropriate solution.