0

I want to use the cv::saliency::MotionSaliencyBinWangApr2014 module. My code is like this:

import cv2

salCV = cv2.saliency.MotionSaliencyBinWangApr2014_create()

frame = cv2.imread(imgfile)
grayFrame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
retval, saliencyMap =   salCV.computeSaliency(grayFrame)

But I get error in pycharm like this:

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

and like this in terminal:

Segmentation fault (core dumped)

What's wrong? How should I use the module cv::saliency::MotionSaliency? Thanks!

ToughMind
  • 987
  • 1
  • 10
  • 28
  • If you're getting a segfault, then the problem is likely somewhere else than your Python code. How did you install this version of OpenCV? What exact version is it? | This also seems to be a contrib module, and those are not as likely to be well tested, so keep that in mind. – Dan Mašek May 27 '19 at 02:40
  • The Python code should probalby check whether `imread` succeeded (just check whether `frame` is not `None`). Won't hurt, although I think the `cvtColor` would complain first. I certainly wouldn't expect to see a sefault here in any case. – Dan Mašek May 27 '19 at 02:42

1 Answers1

-1

This is due to wrong use of that class(I did not intialize it).How to use the saliency module can refer to https://www.pyimagesearch.com/2018/07/16/opencv-saliency-detection/.

import cv2

# initialize the detector
saliency = cv2.saliency.MotionSaliencyBinWangApr2014_create()
saliency.setImagesize(frame.shape[1], frame.shape[0])
saliency.init()

# call the detector
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
(success, saliencyMap) = saliency.computeSaliency(gray)
saliencyMap = (saliencyMap * 255).astype("uint8")
ToughMind
  • 987
  • 1
  • 10
  • 28
  • Link-only answers are considered not useful, since the site you're referring to may change or disappear at any point, therefore making the answer completely useless. Either write up a proper answer, describing the problem and its solution, providing the appropriate attributions to the source, or just delete this. – Dan Mašek May 27 '19 at 02:34