[solved] Does saliency module from opencv_contrib work in python ? [closed]

asked 2017-03-24 10:31:40 -0500

ninamdk gravatar image

updated 2017-03-31 07:34:20 -0500

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
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by ninamdk
close date 2017-03-31 07:51:02.847970

Comments

please show us, what you've tried ;)

also, can you do us a favour, and show the output of

>>> help(cv2.saliency)

? (if so, please add it to your question:)

berak gravatar imageberak ( 2017-03-24 10:38:38 -0500 )edit
1

I just edited my first post :) the output is always a white image

ninamdk gravatar imageninamdk ( 2017-03-24 10:50:43 -0500 )edit

^^ thanks a lot !

berak gravatar imageberak ( 2017-03-24 10:51:50 -0500 )edit

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)

berak gravatar imageberak ( 2017-03-24 11:29:25 -0500 )edit

Thank you for testing this, I guess I will try to find another model less sensitive in that case than the opencv implementation

ninamdk gravatar imageninamdk ( 2017-03-26 09:46:08 -0500 )edit

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.

captain_dave_pdx gravatar imagecaptain_dave_pdx ( 2020-06-19 14:38:50 -0500 )edit