I'm detecting if the camera can see an object in openCV. I want to record the last 10 seconds the object was in scene. I thought about making 2-3 separate videos and deleting and rewriting as it goes. How would that be performance wise? Or is there a way I can keep one video at a set number of frames? I should add that I'm pretty new to openCV
Related
I'm trying to implement a video overlay solution such as this one: https://www.videologixinc.com/, where there is no delay in the original source video.
My problem is that, with OpenCV, all the necessary drawings (circle, text, etc) requires the entire frame to be processed and then returned to be exhibited. Is there any solution where I could just overlay the information in the original source without implying in delay/frame drop? (the additional information can be displayed with delay - drawings, text - but not the original video pipeline).
Multiprocessing could make things faster, but I would still have delay or frame drops.
I was also thinking if would be better to have two simultaneous applications and maybe two different computers - one to read the frame and make the processing - and another one to just receive, somehow, the information to overlay it on the original video pipeline.
Any thoughts? Thank you all!
An example of data pipeline in this case, without interfering in the original video flow
I am trying to program a python OpenCV app for my own use because I can't go to gyms for some time. I would like to do the following:
Capture frames from a video flow using OpenCV [ done ]
Have OpenCV track a yellow soccer and return the coordinate of this soccer in the frame [done]
Come up with an algorithm to detect when a soccer juggling failed, for example the soccer went out of frame and so on [ done ]
Now my question is: let's say I want to save the "10 seconds right before this event" of video into a mp4 file. How should I do it? Is there any good template that I can follow?
Thanks!
You may create a memory buffer worth of 10sec of video (~about 300 frames for most web-cameras), then save frames to that buffer, removing the old ones while adding the new ones.
Once your ball is out of the frame -- open a video file, and save your frames from the buffer.
I'm doing an opencv project which needs to detect a image on the screen, which will disappear after some time it shows up. It needs to save the most amount of frames possible while the image is showing, and stop when it disappears. I plan to use the data collected to do a ConvNet, so the more frames I can capture, the better.
I was using template matching full-screen to search for the image and to identify when it disappears, but I was only capturing about 30% of the total frames, with the screen at 30FPS.
Wanting to increase frame capture rate, I changed to searching full-screen with template matching until the image was found, and then the area for searching was reduced to the coordinates found of the image with a little margin, so the program could identify when the image disapeared using a lot less resources (because of a very smaller área to check if the image was still there). This allowed me to capture 60% of the frames.
However I want to know, can I do something else to allow me to optimize my program? I feel like doing template matching for every frame is overkill. Is object tracking better in this case, or it won't even work because the image disapears?
PS: the image stays for about 7~10 seconds on the screen and takes about the same time to pop up again.
I ended using numpy to save the captured frames and reached 99% efficiency with the reduced area, no resizing of the images or multiprocessing.
I am trying to find the start + end time of a person appears in a video.
My current approach is to find the person using face detection, and then track his face using dlib object tracking (i.e. if the person is turning around in the video, i can't know that he is still in the video using face recognition. Therefore i need both detection and tracking techniques).
The problem is that the object tracking still tracks after an object, even if there was a camera shot cut or scene changed.
So, I tried to initialize the tracking object every shot. But, it's not so easy to detect the shots. even with very high sensitivity, ffmpeg and http://mklab.iti.gr/project/video-shot-segm don't return all of the shot cuts.
So, it turns out that I need to compare the object rectangle of the previous frame, with the rectangle detected in the current frame.
Any idea of a function that can give me a "similarity score" between two rectangles in two frames?
I can open a video and play it with opencv 2 using the cv2.VideoCapture(myvideo). But is there a way to delete a frame within that video using opencv 2? The deletion must happen in-place, that is, the file being played will end up with a shorter time due to deleted frames. Simply zeroing out the matrix wouldn't be sufficient.
For example something like:
video = cv2.VideoCapture(myvideo.flv)
while True:
img = video.read()
# Show the image
cv2.imgshow(img)
# Then go delete it and proceed to next frame, but is this possible?
# delete(img)??
So the above code would technically contain 0 bytes at the end since it reads then deletes the frame in the video file.
OpenCV is not the right tool for this job. What you need for this is a media processing framework, like ffmpeg (=libavformat/libavcodec/libswscale) or GStreamer.
Also depending on the encoding scheme used, simply deleting just a single frame may not be possible. Only in a video consisting of just Intra frames (I-frames), frame exact editing is possible. If the video is encoding in so called group of pictures (GOP) removing a single frame requires to reencode the whole GOP it was part of.
You can't do it in-place, but you can use OpenCV's VideoWriter to write the frames that you want in a new video file.