Jump to content

Recommended Posts

Posted (edited)

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
Posted

smbape, hi!

Thank You for Your work!

If I compile script and try run it as Administrator from standard user account, then it does not work.

Is it possible to fix it?

Posted

I'll tell you my opinion: The launch of the script does not require administrative rights.

Perhaps the user does not have access to images. What error message do you get?

Posted

My random script works correctly when it is launched as you described.

What exactly does not work?

Maybe you want to show your script to see the problem?

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

Posted

The message indicates that you did not specify the variable $img.

Try so. (Now I have Win7 x64).

Local $cv = _OpenCV_get()
Local $img = $cv.imread("pic\lena.png")

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

 

Posted

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.

Posted (edited)

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
Posted

Yes. I run the right mouse button on the file and choose Run As Administrator.

May be You can run it, because You are on windows 7.

Posted

Maybe. And I work with Dlls ver14.

Try and you change "opencv\build\x64\vc15\bin" to "opencv\build\x64\vc14\bin".

I probably can't help anymore.

Posted (edited)

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
Posted

Lion66, I just tested on Windows 7 and it is the same situation as in Windows 10.

Just enable uac and try to run script from regular user with "run as administrator".

Posted (edited)
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
  • 2 weeks later...
Posted (edited)

 

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

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
×
×
  • Create New...