Opened 5 years ago

Closed 4 years ago

#58873 closed defect (invalid)

opencv 3.4.7 broken?

Reported by: renzresearch Owned by:
Priority: Normal Milestone:
Component: ports Version: 2.5.4
Keywords: Cc: stromnov (Andrey Stromnov)
Port: opencv

Description

Upgrading from opencv 3.4.3 to 3.4.7 causes this error:

Traceback (most recent call last):
  File "./Vspline.py", line 116, in <module>
    data = map(alignTile, args)
  File "./Vspline.py", line 43, in alignTile
    cc, warp = cv2.findTransformECC(reference[i:i+h0, j:j+w0], move, init, mode, criteria)
TypeError: Required argument 'inputMask' (pos 6) not found

This does not make sense. inputMask is an optional argument of cv2.findTransformECC. It seems that the python support of opencv 3.4.7 is broken.

Change History (13)

comment:1 Changed 5 years ago by mf2k (Frank Schima)

Port: 3.4.7 removed

comment:2 Changed 5 years ago by mf2k (Frank Schima)

Resolution: invalid
Status: newclosed

You have not provided enough useful information to debug your problem. Please attach the main.log file after cleaning the port (sudo port clean opencv) and re-open the ticket.

comment:3 Changed 5 years ago by renzresearch

Where is main.log?

comment:4 Changed 5 years ago by mf2k (Frank Schima)

$ port logfile opencv

comment:5 Changed 5 years ago by jmroot (Joshua Root)

Resolution: invalid
Status: closedreopened

Isn't this a runtime error, not a build failure? So there won't be a main.log.

comment:6 Changed 5 years ago by renzresearch

I removed opencv and installed it again. The installation had no problem, but no log file can be found.

% port logfile opencv
Error: Log file for port opencv not found

The runtime error remains. cv2.findTransformECC requires an optional argument inputMask. The error message is exactly the same as I posted above.

comment:7 Changed 5 years ago by kencu (Ken)

my first thought is that it's not using the python you think it is using.

could you tell us a "steps to reproduce"?

comment:8 Changed 5 years ago by renzresearch

The previous installation was with +python27 and +python37. cv2 is imported without problem in both python2 and python3. The question on which python is running prompted me to reinstall opencv with only +python27. Now only python2 has this module. I made this minimum test code called testECC.py:

#!/usr/bin/env python
  
import numpy, cv2

mode = cv2.MOTION_EUCLIDEAN
crit = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 50, 0.001)
init = numpy.eye(2, 3,    dtype = numpy.float32)
refe = numpy.ones([4, 5], dtype = numpy.float32)
move = numpy.ones([4, 5], dtype = numpy.float32)

cv2.findTransformECC(refe, move, init, mode, crit)

It reproduces the exact error:

% ./testECC.py 
Traceback (most recent call last):
  File "./testECC.py", line 11, in <module>
    cv2.findTransformECC(refe, move, init, mode, crit)
TypeError: Required argument 'inputMask' (pos 6) not found

comment:9 Changed 5 years ago by kencu (Ken)

#! /usr/bin/env python is not necessarily specific enough. It often will go to the system python, or another python. Whichever one comes up first in the path. You can find the one that will be used with which python.

How about try your script by referencing the exact python you want:

/opt/local/bin/python2.7

and see how that works for you.

You can also modify which python is used with

$ port select --list python
Available versions for python:
	none
	python25-apple
	python26-apple
	python27 (active)
	python34
	python35
	python36
	python37

and then do this to force one of them to the one you want python to be:

sudo port select python python27

comment:10 Changed 5 years ago by renzresearch

I have checked these:

% which python
/opt/local/bin/python
renz:~ % ls -l /opt/local/bin/python
lrwxr-xr-x  1 root  wheel  24 Dec 28  2018 /opt/local/bin/python -> /opt/local/bin/python2.7

I also did this:

% /opt/local/bin/python2.7 testECC.py 
Traceback (most recent call last):
  File "testECC.py", line 11, in <module>
    cv2.findTransformECC(refe, move, init, mode, crit)
TypeError: Required argument 'inputMask' (pos 6) not found

So the correct python is running.

comment:11 Changed 5 years ago by kencu (Ken)

So - I get the same.

This <https://answers.opencv.org/question/212409/error-in-findtransformecc/> suggests you actually do need to pass all the parameters, and can't skip them, when using python at least.

This version of your code doesn't generate a runtime error (but doesn't actually compute out to a good answer, sorry):

#!/usr/bin/env python
  
import numpy, cv2

mode = cv2.MOTION_EUCLIDEAN
crit = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 50, 0.001)
init = numpy.eye(2, 3,    dtype = numpy.float32)
refe = numpy.ones([4, 5], dtype = numpy.float32)
move = numpy.ones([4, 5], dtype = numpy.float32)

cv2.findTransformECC(refe, move, init, mode, crit, None, 5)

gives:

$ ./testECC.py
Traceback (most recent call last):
  File "./testECC.py", line 11, in <module>
    cv2.findTransformECC(refe, move, init, mode, crit, None, 5)
cv2.error: OpenCV(3.4.7) /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_graphics_opencv/opencv/work/opencv-3.4.7/modules/video/src/ecc.cpp:557: error: (-7:Iterations do not converge) NaN encountered. in function 'findTransformECC'

So -- looks like the function needs to have something sent along to it in the 6 & 7 positions, and looks like the MacPorts implementation of opencv is not actually broken.

comment:12 Changed 5 years ago by kencu (Ken)

In the opencv docs, it looks like the python definition of the function changed from 3.4.5 to 3.4.7, and the last two function parameters appear to no longer be optional.

See <https://docs.opencv.org/3.4.5/dc/d6b/group__video__track.html#ga7ded46f9a55c0364c92ccd2019d43e3a>

vs

<https://docs.opencv.org/3.4.7/dc/d6b/group__video__track.html#ga7ded46f9a55c0364c92ccd2019d43e3a>

This page <https://docs.opencv.org/3.4.7/da/d49/tutorial_py_bindings_basics.html> shows how the python bindings are generated.

So, it appears to me that if you'd like the previous optional parameter behaviour, you'll need to ask upstream for them to fix that.

comment:13 Changed 4 years ago by ryandesign (Ryan Carsten Schmidt)

Resolution: invalid
Status: reopenedclosed

So, not a MacPorts bug.

Note: See TracTickets for help on using tickets.