Jump to content

OpenCV v4 UDF


smbape
 Share

Recommended Posts

Hi @Lion66

You are right when you say.

7 hours ago, Lion66 said:

In my original file, the picture is not called when script is started, so there is no problem.

When you said

On 11/8/2021 at 7:33 PM, Lion66 said:

One example I know has a logical problem (extra\Find-Contour-Draw-Demo.au3) :
when the script is started, the picture is automatically called, but the object $sObject remains empty.

I though you were talking about the fact that $sObject is empty despite the call _ReadImg()
That is why I put _ReadImg() at the begining in your script and said there is the same error.

The error comes from the fact that in _ReadImg, $sSource is used instead of $sObject.
If you replace $sSource with $sObject in _ReadImg function, it works.

The use of $sSource instead of $sObject is what I thought was the logical error you were refering to.

Sorry for the misunderstanding.

Edited by smbape
Link to comment
Share on other sites

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

Opt("MustDeclareVars", 1)

#include "autoit-opencv-com\udf\opencv_udf_utils.au3"

_OpenCV_Open_And_Register("opencv-4.5.4-vc14_vc15\opencv\build\x64\vc15\bin\opencv_world454.dll", "autoit-opencv-com\autoit_opencv_com454.dll")

Local $cv = _OpenCV_get()

If IsObj($cv) Then
    $cv.imshow("Image", $img)
    $cv.waitKey()
    $cv.destroyAllWindows()
EndIf

_OpenCV_Unregister_And_Close()

If I compile this script and run from regular user - it of course will show error. That is right.

Quote

 

---------------------------
AutoIt Error
---------------------------
Line 18999  (File "C:\Users\test\Desktop\test\New AutoIt v3 Script.exe"):


Error: Variable used without being declared.
---------------------------
OK   
---------------------------

 

So it means that com is registered.

But if I run the same script from regular user with "run as Administrator" - then it shows nothing,  just exits.

That means that com was not registered.

I tested it on win10.

Link to comment
Share on other sites

No. You dont understand me.

If We see this error message - then script works OK.

It means that com object is registered successful.

But If We dont see this error, it means that $cv is not object.

And therefore I asked author is it possible to fix it.

Link to comment
Share on other sites

I have the same manner on the Administrator, on the User and on User Runas Administrator.

And I do not see the reasons for it to work otherwise.

You run the right mouse button on the file and choose Run As Administrator?

Or somehow differently, through the script?

Edited by Lion66
Link to comment
Share on other sites

HI @malcev
Thank you for your interest.

I your error is

3 hours ago, malcev said:

Error: Variable used without being declared.

then you used a variable without having it declared. It is the effect of

Opt("MustDeclareVars", 1)

Now concerning registration, running as administrator is not necessary.

Can you do the following checks:

  • Add in you script, after the #include, $_cv_debug = 1
  • Run the script
  • In the command prompt, as a normal user,
    SET "PATH=<fullpath to opencv-4.5.4-vc14_vc15\opencv\build\x64\vc15\bin>;%PATH%"
    regsvr32 /n /i:user <full path to autoit_opencv_com454.dll>
    regsvr32 /u /n /i:user <full path to autoit_opencv_com454.dll>

Can you come back with the results?

Edited by smbape
typo
Link to comment
Share on other sites

2 hours ago, malcev said:

Why do You register clsid into HKEY_CURRENT_USER?

_OpenCV_Open_And_Register and _OpenCV_Unregister_And_Close have an additional parameter "$user".
When this parameter is True, which is the default value, the application redirects registry access to the HKEY_CURRENT_USER (HKCU) node.

For me, a program that requires admin autorisation should be treated with security concerns.
That is why, by default, the script should not be executed as administrator.

If you really need to execute the script as an administrator, the are some options for you:

  • Register the classes before running the script. You can either register classes for all users or for the current user (come back to me if you have no idea of how to do it).
    Then use _OpenCV_Open instead of _OpenCV_Open_And_Register and use _OpenCV_Close instead of _OpenCV_Unregister_And_Close
    With this option, your script can run both as administrator and as non administrator.
    With this option, your script will be faster to start.
    With this option, on every udf update, you should first unregister the old classes, then register the new classes
  • Set the $user parameter of _OpenCV_Open_And_Register and _OpenCV_Unregister_And_Close to False.
    With this option, your script can only be run as an administrator.
  • Detect wheter the script is run as an administrator or not, and depending of the case, set the $user parameter to the correct value.
Edited by smbape
Link to comment
Share on other sites

  • 2 weeks later...

 

Do you know how to convert a opencv image to a gdi hbitmap, and if them would takes lesss size on RAM or at the end would be the same thing as using by default a bitmap>hbitmap using just GDI?

I'm storing some hbitmaps in memory but they are using too much RAM, i wonder ifs possible somehow do any kind of compression on them converting opencv > hbitmap?

 

Edited by memerim
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...