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

Open CV - SuperPixel - Attribute Error / Complex type mapping #9

Open
kartus42 opened this issue Jul 22, 2022 · 10 comments
Open

Open CV - SuperPixel - Attribute Error / Complex type mapping #9

kartus42 opened this issue Jul 22, 2022 · 10 comments
Assignees

Comments

@kartus42
Copy link

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

image

  • 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?

image

here is the project code

OpenCV_2.zip

thank you

@peardox
Copy link
Contributor

peardox commented Jul 25, 2022

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)

@peardox
Copy link
Contributor

peardox commented Jul 25, 2022

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 :)

@lmbelo lmbelo self-assigned this Jul 25, 2022
@lmbelo
Copy link
Member

lmbelo commented Jul 25, 2022

@peardox,

we are currently working to launch the Discord channel to the community. We expect to get it widely used by the community.

@lmbelo
Copy link
Member

lmbelo commented Jul 27, 2022

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

image

  • 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?

image

here is the project code

OpenCV_2.zip

thank you

@kartus42 I will try it and be back with a feedback.

@lmbelo
Copy link
Member

lmbelo commented Jul 27, 2022

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.

@peardox
Copy link
Contributor

peardox commented Jul 27, 2022

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
Copy link
Contributor

peardox commented Jul 27, 2022

@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)

@peardox
Copy link
Contributor

peardox commented Jul 28, 2022

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...

OpenCV_2_sorta_fixed.zip

@peardox
Copy link
Contributor

peardox commented Jul 28, 2022

@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...)

@peardox
Copy link
Contributor

peardox commented Aug 1, 2022

@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)

@peardox peardox mentioned this issue Aug 5, 2022
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

3 participants