P4D-Data-Sciences
P4D-Data-Sciences copied to clipboard
Open CV - SuperPixel - Attribute Error / Complex type mapping
Hi gents,
I am continuing my OpenCV / Python / Delphi journey and found the following:
- It seems that createSuperpixelLSC cannot be used as raised the following error, or maybe I don't use correct syntax
- I also try to use Hough transform, that seems to work pretty well except that I am struggling to find the proper way to use received output. I see it is a vector list but I don't know equivalent type in Delphi, can you help ? More generally is there a way to handle type conversion?
here is the project code
thank you
I can't help but notice that this appears to be higher up the chain than you state as the error message you've got says you're missing the attribute 'ximgproc'
I'll have a little fiddle as I'm going to be wanting OpenCV2 myself in a while.
Your better bet may be @lmbelo though as he writes this stuff in the first place (while I'm blindly working stuff out as I go)
Well, that was quick...
Googling "python cv2 ximgproc" finds the problem instantly at https://stackoverflow.com/questions/57427233/module-cv2-cv2-has-no-attribute-ximgproc
It notes that....
- There are 4 different opencv packages: opencv-python, opencv-contrib-python, opencv-python-headless, opencv-contrib-python-headless.
- You can only install one. Multiple opencv packages are incompatible.
So, you've using the wrong OpenCV
This can be fixed simply by working out which particular variant of OpenCV you need and creating a Package for it - e.g. cv2_contrib (or whichever one you need)
Creating the required package is very easy (and like everything else completely undocumented). Just need to know which package you're after (I'll try working it out - may need it myself). Opencv-contrib-python looks like a likely candidate from that StackOverflow anyway - I'll whip up a quick package.
@lmbelo Making the fact there's a Discord public might be a good idea as issues like this are better placed there. I'm sure that more people than the four current members of it would like to know it existed :)
@peardox,
we are currently working to launch the Discord channel to the community. We expect to get it widely used by the community.
Hi gents,
I am continuing my OpenCV / Python / Delphi journey and found the following:
- It seems that createSuperpixelLSC cannot be used as raised the following error, or maybe I don't use correct syntax
- I also try to use Hough transform, that seems to work pretty well except that I am struggling to find the proper way to use received output. I see it is a vector list but I don't know equivalent type in Delphi, can you help ? More generally is there a way to handle type conversion?
here is the project code
thank you
@kartus42 I will try it and be back with a feedback.
Well, that was quick...
Googling "python cv2 ximgproc" finds the problem instantly at https://stackoverflow.com/questions/57427233/module-cv2-cv2-has-no-attribute-ximgproc
It notes that....
- There are 4 different opencv packages: opencv-python, opencv-contrib-python, opencv-python-headless, opencv-contrib-python-headless.
- You can only install one. Multiple opencv packages are incompatible.
So, you've using the wrong OpenCV
This can be fixed simply by working out which particular variant of OpenCV you need and creating a Package for it - e.g. cv2_contrib (or whichever one you need)
Creating the required package is very easy (and like everything else completely undocumented). Just need to know which package you're after (I'll try working it out - may need it myself). Opencv-contrib-python looks like a likely candidate from that StackOverflow anyway - I'll whip up a quick package.
@lmbelo Making the fact there's a Discord public might be a good idea as issues like this are better placed there. I'm sure that more people than the four current members of it would like to know it existed :)
@peardox found the answer.
You can use the current implementation of OpenCV and install it from a different index-url.
I wrote the requited component after replying to this but messed naming up.
I got close but need to alter the component slightly (then I rented a M1 so didn't get a chance to look at this again yet)
I do, however, now that he requires an alternate package, preferably PIP, and probably this one - opencv-contrib-python
As noted above there are four cv2 packages and all break the others so he needs thee correct package.
@peardox found the answer.
You can use the current implementation of OpenCV and install it from a different index-url.
That's a good point. Hmm - selectable sources would be a nice feature for cases like this. I know from experience that PyTorch needs an extra-index-url for GPU support that changes every so often (I've seen three recently - the oldest one hits deprecated when a new one arrives from the look of it)
Here you go - one working (almost) version of your progette
There's an extra component called CV2_Contrib in the folder p4d-extras/packages that you'll need to install
Annoyingly cv2 is known as np in this component - not sure why (@lmbelo - I called it cv2 but the thing only responds to np) - could be something to do with opencv-contrib-python or the Delphi interface to it (ain't got a clue and as it works ain't really worried about it)
I had to comment out this loop (low/high on Variant)
for low(lines) to high(lines) do
begin
// x1,y1,x2,y2 from lines[0]
img:= np.line(img,(x1,y1),(x2,y2),(0,255,0),2)
end;
It now compiles and at least rotates the image. It also has createSuperpixelLSC which is what you were after.
Your code back, slightly modified with a new working component...
@peardox found the answer. You can use the current implementation of OpenCV and install it from a different index-url.
That's a good point. Hmm - selectable sources would be a nice feature for cases like this. I know from experience that PyTorch needs an extra-index-url for GPU support that changes every so often (I've seen three recently - the oldest one hits deprecated when a new one arrives from the look of it)
Tried it - didn't work, Re-implemented component (which does work)
PIP gets upset if you give it the contrib url as it doesn't match the required package - at least in my non-specialist tests (it will be possible, just not the way I tried it...)
@kartus42 I've now added a PR so hopefully a nice new component will appear fairly soon for you. I also found out why it was wanting to be called np (I copied Numpy - doh...) in my quick component and fixed that (so it's now correctly cv2 again)