Jump to content

Recommended Posts

  • Replies 141
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

I wanted to use OpenCV v4+ in AutoIt. I found Opencv UDF on the forum, but there was no support for OpenCV v4+ This UDF provides support for OpenCV v4+ Update There is a new implem

If you mean having a subset of $contours that validates the condition on _cveContourAreaTyped, then it is Local $good_contours = _VectorOfVectorOfPointCreate() Local $tVectorPointPtr2 =

Update opencv to 4.6.0

Posted Images

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 post
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 post
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 post
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 post
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 post
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 post
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 post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By JoGa
      Greetings,
      here is a Autoit3 v3.3.14.5, 64 Bit installation on windows 10 with current updates.
      In a simple script I'm Dllcall'ing a 64 bit dll.
      # T1.au3 Local $name = "T1DLL.dll" if (FileExists($name)) Then ConsoleWrite("DLL '" &$name &"' exists" &@CRLF) EndIf Local $DLL = DllOpen($name) if (@ERROR OR $DLL = -1) then ConsoleWrite("DllOpen ERROR=" &@ERROR &" DLL=" &$DLL &@CRLF) Else ConsoleWrite("DllOpen Success" &@CRLF) endif DllCall($DLL, "none:cdecl", "SomeFunction", "str", "DLL Call from T1.au3") if (@ERROR) then ConsoleWrite("DllCall ERROR=" &@ERROR &" DLL=" &$DLL &@CRLF) Else ConsoleWrite("DllCall Success" &@CRLF) endif The C code contains one 64 bit OpenCV call:    cv::destroyAllWindows();.

      Excuting T1.au3 with SciTE gives:

      If the c code is compiled *without* the OpenCV call T1.au3 runs successful:
       
      I checked T1DLL.dll, it's definitely a 64 bit dll.
      What could cause the problem?
      Any hint would be very much appreciated.
      Thanks
      Wolf
       
       
       
       
    • By BBs19
      I needed a function to automate programs at work that can't be fully automated via Autoits built in functions.
      For example a virtual machine running on your physical machine, meaning you would need to run an extra script within the virtual machine (if it is even running Windows) in order to automate everything.
      I came across OpenCV which allows matching/finding a picture in another picture. This would also allow searching for a button/text on the screen in order to press the exact position. Fortunately @mylise already translated all the required OpenCV functions to Autoit, I just had to remove all unnecessary functions to make the script as small as possible.
      The problem:
      Using this method, you will never be able to fully automate everything dynamically, as it will only work on the machine with same resolution/dpi settings, same theme etc.. This is only a last resort for programs that can't be automated using the built in Autoit functions.
      Features:
      Find a given picture on the entire screen (all monitors) or a certain area on the screen and execute mouse clicks on this position. Adjust the threshold so that the picture doesn't have to match 100%. Debugging options like logging and marking the screen where the picture was found etc. Includes a Snapshot-Tool that creates snapshots of a certain area(buttons, text etc.) on the screen and generates the code that is required for the matching. It can also be used to get the coordinates to a marked area on the screen in order to check only on a certain area for the match picture. Example:
      Note: The example will probably not work on your computer, depending on the display resolution and dpi settings, as the picture has to match the exact same size on the screen. Please use the included Snapshot-Tool to generate new match pictures and code very easily.
      #AutoIt3Wrapper_UseX64=n ; In order for the x86 DLLs to work #include "OpenCV-Match_UDF.au3" _OpenCV_Startup();loads opencv DLLs _OpenCV_EnableLogging(True,True,True) ;Logs matches, errors in a log file and autoit console output. ;Please note that these examples might not work as the match pictures have to be found with the exact same size on your screen. ;Example 1 ShellExecute("http://www.tv.com/");Open Website tv.com $Match1 = _MatchPicture(@ScriptDir&"\Match\1.png", 0.70,False,10,500);Try to find the match picture on the screen. Number of tries: 10, Sleep between each try: 500ms. If Not @error Then _MarkMatch($Match1) ;Debugging: Draws a rect on the screen/coordinates of the match to show the user where the match was found Sleep(100) _ClickMouse($Match1, "left",1) ;Calculates the center of the match and clicks the left mouse once on click position EndIf Sleep(1000) ;Example 2, matching on a specific area of the screen ShellExecute("notepad.exe");open nodepad WinWait("[CLASS:Notepad]","",5) WinMove("[CLASS:Notepad]","",0,0,500,500) Local $sCoords[4] = [0, 0, 500,500] $Match2 = _MatchPicture(@ScriptDir&"\Match\2.png", 0.80,$sCoords,3,500) If Not @error Then _MarkMatch($Match2) Sleep(100) _ClickMouse($Match2, "left", 1) EndIf _OpenCV_Shutdown();Closes DLLs So basically, all you need to do is provide a path to the match picture and the function will return you the coordinates (x1,y1,x2,y2) of where the picture has been found on the screen. With these, you can either calculate an exact position for the mouse click or use the "_ClickMouse" function which will execute a mouse click on the center of the coordinates where the picture was found. 
      Credits:
      @mylise for the OpenCV UDF
       
      Download:
      Includes the required .DLL files of OpenCV. You can also manually download them on the website of OpenCV (Version 3.x doesn't include these anymore, you need to download 2.x).
      OpenCV_Match.zip
×
×
  • Create New...