[solved] Does saliency module from opencv_contrib work in python ? [closed]
Hi,
I am trying the Motion saliency algorithm in the Saliency module from Opencv_contrib (in python) but it doesn't seem to work. I didn't find any example on how to use the python wrapping of these functions. Did anyone try it before and can help me figure out what's wrong ?
Thank you EDIT!:
The code I tried:
import cv2
import skvideo.io
video = skvideo.io.VideoCapture(video_file)
_, img = video.read()
imgsize = img.shape
saliency = cv2.saliency.MotionSaliencyBinWangApr2014_create()
saliency.setImagesize(imgsize[0], imgsize[1])
saliency.init()
while True:
success, img = video.read()
if success:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
out = saliency.computeSaliency(gray)
cv2.imshow("sal", out[1]*255)
else:
break
The output is a white image
output of help(cv2.saliency)
Help on module cv2.saliency in cv2:
NAME
cv2.saliency
FILE
(built-in)
FUNCTIONS
MotionSaliencyBinWangApr2014_create(...)
MotionSaliencyBinWangApr2014_create()
-> retval
ObjectnessBING_create(...)
ObjectnessBING_create() -> retval
StaticSaliencyFineGrained_create(...)
StaticSaliencyFineGrained_create() -> retval
StaticSaliencySpectralResidual_create(...)
StaticSaliencySpectralResidual_create()
-> retval
please show us, what you've tried ;)
also, can you do us a favour, and show the output of
? (if so, please add it to your question:)
I just edited my first post :) the output is always a white image
^^ thanks a lot !
i tested from c++, and found it's just very sensitive to motion.
(in other words, i think, your code is correct, more like the used model is a bit hypersensitive)
Thank you for testing this, I guess I will try to find another model less sensitive in that case than the opencv implementation
I had the same problem (white image). To fix it, I realized I had set "cv2.waitKey" to 0, which meant it would only show one image frame until any key was pressed. By holding down any key, and keeping my body still in the frame, the image started to render. Later, I changed "cv2.waitKey" to 1, which showed a new frame every 1 millisecond, and the image started to render on its own.