Comments (5)
The project should register pickling functions with the copyreg
module. See my Stack Overflow answer for example on how to write one.
The underlying cause is that the __name__
attribute on the class of instances returned by functions such as cv2.Boost()
points back to the function, not the actual type. The other work-around would be for the __name__
attribute to actually resolve back to the correct type.
from opencv.
Very helpful. Thanks ! Your stackoverflow answer is really clear.
Here is the code snippet for Keypoints, as the same problem occurs for them :
def patch_Keypoint_pickiling(self):
# Create the bundling between class and arguements to save for Keypoint class
# See : https://stackoverflow.com/questions/50337569/pickle-exception-for-cv2-boost-when-using-multiprocessing/50394788#50394788
def _pickle_keypoint(keypoint): # : cv2.KeyPoint
return cv2.KeyPoint, (
keypoint.pt[0],
keypoint.pt[1],
keypoint.size,
keypoint.angle,
keypoint.response,
keypoint.octave,
keypoint.class_id,
)
# KeyPoint (float x, float y, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1)
# Apply the bundling to pickle
copyreg.pickle(cv2.KeyPoint().__class__, _pickle_keypoint)
from opencv.
Just got caught by this one as well, although a different class:
Can't pickle <class 'cv2.CascadeClassifier'>: it's not the same object as cv2.CascadeClassifier
How is a fix coming together? Any help needed?
from opencv.
There are a few issues with python serialization (pickle/copy) and opencv. I'll be using the class KeyPoint for the examples.
- Currently the generated c-api code defines the C++ classes as both a python function and a python class (which isn't registered in the cv2 module, altough it's name is "cv2.". To my knowledge this is a big no-no and will block using the pickle subsystem at all.
- There is no reduce / copy_reg.pickle code generated for how to serialize the objects themselves (for saving/loading the actual object state).
>>> import cv2
>>> kp = cv2.KeyPoint(1, 2, 3)
>>> type(kp)
<type 'cv2.KeyPoint'>
>>> type(kp) == cv2.KeyPoint
False
>>> cv2.KeyPoint
<built-in function KeyPoint>
>>> import pickle
>>> pickle.dumps(kp, -1)
pickle.PicklingError: Can't pickle <type 'cv2.KeyPoint'>: it's not the same object as cv2.KeyPoint
I assume the only correct solution (unless I'm wrong) is to:
- Stop using the creation functions (like pyopencv_KeyPoint_KeyPoint) and instead create a true new and init implementations for all the cv2 classes and register them in cv2 instead of the creation functions.
- Implementing a auto generated reduce function for each of the classes.
I am not versed enough in the complex code of the gen2.py (especially it's edge cases), so if someone could shed more light on this issue (for example, is there an easier solution which is also as correct ?)
from opencv.
this "bug" caught me, too.
from opencv.
Related Issues (20)
- RISC-V: instructions executed count increases linearly with VLEN size HOT 11
- OpenCV(4.7.0) :- not read caffe model
- When creating a framework for VisionOS, specifying "--dynamic" argument causes a build error. HOT 1
- terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.5.4) ./modules/dnn/src/onnx/onnx_importer.cpp:739: error: (-2:Unspecified error) in function 'handleNode' > Node [Identity]:(onnx::Reshape_395) parse error: OpenCV(4.5.4) ./modules/dnn/src/dnn.cpp:5653: error: (-215:Assertion failed) inputs.size() in function 'getMemoryShapes' HOT 4
- Failed to load module gail and atk-bridge while compiling a simple C++ program HOT 2
- When binding APIs in opencv.js, corresponding structs/enums should be bound HOT 1
- cv2.CAP_ANY (MSMF) not support high resolution webcam HOT 2
- Possible bug / precision issue in normalize() HOT 2
- Buildroot cross compile on Debian12 + ccache: fatal error: stdlib.h: No such file or directory
- imwrite() to TIFF does not use COMPRESSION_SGILOG for 32FC1 (only 32FC3) HOT 6
- Lens distortion documentation unclear HOT 2
- OpenCV conflict problem for Window popup HOT 3
- Missing typing stub: cv2.SIFT_create()
- Extract inliers from HL Image Stitcher HOT 2
- 3rdparty: Small version expression problems for built-in tiff460
- crash when invoke cv2.intersectConvexConvex HOT 3
- The performance of `cv::parallel_for_` is quite low on Windows HOT 1
- I can not use the "cv::imshow()" fucntion HOT 4
- the function of cv2.denoise_TVL1 HOT 2
- `SIGBUS` crash in `pointSetBoundingRect()` on ARMv7-A (armeabi-v7a) due to unaligned NEON load HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opencv.