Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenCV-Python] On Windows, Tracker.write() raises error in matrix_wrap.cpp, Tracker.read() crashes Python #2405

Open
dickjackson opened this issue Jan 12, 2020 · 1 comment

Comments

@dickjackson
Copy link

System information (version)
  • OpenCV => 4.2.0
  • Operating System / Platform => Windows 10, 64 Bit
  • Compiler => Visual Studio 16 2019
  • Python => 3.7.6, using Anaconda
Detailed description

I would like to use the Tracker classes from Python on Windows, and it seems that in Python the only way to access algorithm parameters is by writing/reading the Tracker object to/from a .yaml file. When I try Tracker.write(), I get a cv2.error. Here is my test case:

Steps to reproduce
import cv2
import os

#Display OpenCV version
print(f"OpenCV version: {cv2.__version__}")

#Create tracker object
tracker = cv2.TrackerCSRT_create()

settings_file = "settings.yaml"

#Delete settings file if it exists
if os.path.isfile(settings_file): os.remove(settings_file)

#Create FileNode
fs = cv2.FileStorage(settings_file,cv2.FILE_STORAGE_WRITE)

#Write defaults
tracker.write(fs)

#Release file
fs.release()

When I tried this (Python 3.7.6, OpenCV 4.2.0… with prepackaged binaries, or when rebuilt from source code), it failed on the tracker.write(fs) line with this message:

Traceback (most recent call last): File "<stdin>", line 1, in <module> cv2.error: OpenCV(4.2.0) C:\Users\dick\OpenCV\opencv-4.2.0\modules\core\src\matrix_wrap.cpp:112: error: (-213:The function/feature is not implemented) You should explicitly call mapHost/unmapHost methods for ogl::Buffer object in function 'cv::_InputArray::getMat_'

On a slightly different test, I got this error message:

Traceback (most recent call last): File "<stdin>", line 5, in <module> cv2.error: OpenCV(4.2.0) C:\Users\dick\OpenCV\opencv-4.2.0\modules\core\src\matrix_wrap.cpp:130: error: (-213:The function/feature is not implemented) Unknown/unsupported array type in function 'cv::_InputArray::getMat_'

I have a friend who is more C++/Linux/Visual Studio savvy than I am, and she confirmed for me that this tracker.write() works fine on Linux, writing a .yaml file, as does using tracker.read() to read it back as follows:

#Read in the settings
fs_settings = cv2.FileStorage(settings_file,cv2.FILE_STORAGE_READ)
tracker.read(fs_settings.root())

#Release file
fs_settings.release()

When I try tracker.read() with a known-good .yaml file, Python crashes straight to the command prompt—no error message at all. I guess this is a closely related issue.

My friend's assessment was "As far as I can tell, in Windows the Mat object being created is the wrong datatype (whether is it has an extra dimension or wrong type (i.e. float vs int) or it's an empty null pointer).", and I've imposed on her time quite enough to this point. Could someone please look into the C++ code to see what's going wrong, and perhaps why it works on Linux but not Windows?

In looking around for similar issues, I thought that #2393 looked somewhat familiar, where the Mat class wasn't behaving as expected.

[Note: This is my first time opening an issue, I'm not fluent in C++ or using VS (I got a lot of help to do the recompiling!), and I'm still learning Python—I hope the OpenCV team will support Python end-users like me to access tracking algorithm parameters, even if they have no option but Windows. :-) Thank you.]

@9autilus
Copy link

9autilus commented Jul 2, 2020

Hey, I just solved this problem by downgrading to opencv-contrib-python version 3.3.0.9. Dropping link to my StackOverflow answer for further information. Overall, here is the log of versions that pass/fail with this bug:

3.2.0.7
3.2.0.8

3.3.0.9 pass
3.3.0.10
3.3.1.11

3.4.0.12 pass
3.4.0.14
3.4.1.15
3.4.2.16 pass
3.4.2.17
3.4.3.18
3.4.4.19 pass
3.4.5.20 pass
3.4.6.27 pass
3.4.7.28 fail
3.4.8.29 fail
3.4.9.31 fail
3.4.9.33

4.0.0.21 pass
4.0.1.23
4.0.1.24
4.1.0.25 pass
4.1.1.26 fail
4.1.2.30 fail
4.2.0.32
4.2.0.34 fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants