I am working on a project that aims to extract the "interesting" sequences from an mp4 video using different concepts.
One of them is supposed to be the image entropy and right now, I am a bit stuck.
I have followed this tutorial to get the entropy for a few selected screenshots from the video: https://scikit-image.org/docs/dev/auto_examples/filters/plot_entropy.html
For that, I got results like this one which is what I wanted.
To apply it to my test video, I did the following:
import cv2
from skimage.filters.rank import entropy
from skimage.morphology import disk
# Creating a VideoCapture object to read the video
video = cv2.VideoCapture('mypath/samplevideo.mp4')
if not video.isOpened():
print("Error reading video file")
width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
size = (width, height)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
result = cv2.VideoWriter('filename.avi', cv2.VideoWriter_fourcc(*'VIDX'), 30, size)
# Loop until the end of the video
while video.isOpened():
# Capture frame-by-frame
ret, frame = video.read()
# Display the resulting frame
cv2.imshow('Frame', frame)
# apply the entropy to each frame
img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
entropy_frame = entropy(img, disk(5))
cv2.imshow('Entropy', entropy_frame)
result.write(entropy_frame)
# define q as the exit button
if cv2.waitKey(25) & 0xFF == ord('q'):
break
# release the video capture object
video.release()
result.release()
# Closes all the windows currently opened.
cv2.destroyAllWindows()
This code yields two windows, one with the original video (as wanted) and one that is supposed to show the same video but with the image entropy applied. At the end, it is supposed to save the entropy video. What I get right now in the "entropy window" is something like this (left is the original video, right the entropy) which does not at all look like the result I want.
What can I fix to get the result that I want? Thanks in advance