Jump to content

Recommended Posts

Hi @memerim

On 1/27/2022 at 3:47 AM, memerim said:

Do you know how to convert a opencv image to a gdi hbitmap

Local $img = $cv.imread("path image")
Local $hBitmap = $img.convertToBitmap()

 

On 1/27/2022 at 3:47 AM, memerim said:

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?

Probably more, depending on the color conversion and it is the same thing as converting bitmap to hbitmap.

 

On 1/27/2022 at 3:47 AM, memerim said:

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?

You did not give what you call too much RAM.
I assume your image is big ( > 100MB), if not, then you probably have a memory leak somewhere.
When using GDI+ with AutoIt, beware of memory leaks.

There are multiple ways to reduce memory usage, at the price of less accurate results. Some ways are:

  • Resize the image
  • Read the image in grascale
  • Threshold the image (may be canny)
  • Blur the image

You have to test those ways to see what combination gives the best results.

Edited by smbape
Link to post
Share on other sites
  • 2 weeks later...
  • Replies 138
  • 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

When you assign a value to a variable, the variable is set. However, your phrase makes me think that it is not what you mean. Can you explain? 7b is hard to translate since it involves manipu

_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

Posted Images

Hello smbape. I'd like to thank you for putting quite a bit of effort to bringing OpenCV to AutoIt. After some time I was able to get all of your examples to work as intended. In fact, I've carefully read every currently available OpenCV AutoIt thread but it feels as if I hit a brick wall. I'm using _OpenCV_FindTemplate for my driveway security camera feed. It functions well but various changes in weather and time of day really mess with it.

Let's say I'm trying to consistently detect my blue Ford on the driveway whether it's further away from the house or much closer to the camera. How do we apply scale and color to objects?

From my extensive search combined with trial and error I'm quite certain I need to use HSV. After studying the cv_enums.au3 I found $CV_COLOR_RGB2HSV. Afterwards, I've carefully looked into opencv_udf_utils.au3, specifically for the format inside the parameters it accepts. I've narrowed it down to the following four parameters:

$threshold
$aChannels
$aHistSize
$aRanges

Threshold is straightforward and I fully grasp the concept, however, the other three are confusing to me. I understand photo editing, RGB channels, alpha channels with transparency but using this in OpenCV is above my pay grade. I've tried using the following with every parameter I could think of but not to much difference in results:

; [0] for gray-scale images as there's only one channel and [0], [1] or [2] for color images
; if we want to consider the channel green, blue or red respectively
Local $aChannels[3] = [0, 1, 2]

; Quantize each color to 32 levels
; The higher the value, the closer to the template the matched color is
Local $aHistSize[3] = [32, 32, 32]

; the range of the possible pixel values which is [0, 256] in case of RGB color space (where 256 is not inclusive)
Local $aRanges[6] = [0, 256, 0, 256, 0, 256]

_OpenCV_FindTemplate($img, $tmpl, $threshold, $CV_TM_SQDIFF_NORMED, Default, 8, $CV_COLOR_BGRA2BGR, 1, $aChannels, $aHistSize, $aRanges)

I was hoping for some guidance from you given your experience with the topic. Thank you!

Link to post
Share on other sites
19 minutes ago, OhItsThatGuy said:

various changes in weather and time of day really mess with it.

I dont know how to do it with OpenCV, but usually you would constantly update the reference image.

Like you have your refence image and a new image comes in that needs to be compared with the reference image, if there are no big changes, then the new image shall become the new reference image, automatically adapting to weather and time of day changes.

Some guy's script + some other guy's script = my script!

Link to post
Share on other sites

Hi @OhItsThatGuy

On 2/9/2022 at 11:21 PM, OhItsThatGuy said:

How do we apply scale and color to objects?

There are 2 ways to resize an image:

  • Use opencv resize Ex: $img_resized = $cv.resize($img, _OpenCV_Size($iWidth, $iHeight), $flags = $CV_INTER_LINEAR, $borderMode = $CV_BORDER_CONSTANT)
  • Use GDI+ resize, Ex: $img.GdiplusResize($iWidth, $iHeight, $interpolation = 7). Better quality but slower.

Concerning colors, to convert an image between color spaces, you can use cvtColor

$cv.cvtColor($img, $CV_COLOR_RGB2HSV)

Try with HSV or Lab, you may have better results.
_OpenCV_FindTemplate has a color conversion parameter, $iCode, no need to do the conversion on your own

On 2/9/2022 at 11:21 PM, OhItsThatGuy said:

Threshold is straightforward and I fully grasp the concept, however, the other three are confusing to me. I understand photo editing, RGB channels, alpha channels with transparency but using this in OpenCV is above my pay grade. I've tried using the following with every parameter I could think of but not to much difference in results:

Those parameters are only used when the match method is not normed, meaning not one of $CV_TM_SQDIFF_NORMED Or $CV_TM_CCORR_NORMED Or $CV_TM_CCOEFF_NORMED
In those cases, an histogram comparison is done using those parameters.

More over, taking into account what @Werty said, try to have multiple templates for different weather and time.
A simple alorigthm will be, if not raining and time between 10AM and 2PM, use "template 1", if time between 6PM AND 23PM use "template 2"

I hope it will help.

Edited by smbape
Link to post
Share on other sites

Hi @malcev

17 hours ago, malcev said:

Dont You plan to bind dlib or mediapipe to autoit in future?

I tried in the past, however, on windows, there was no dll for dlib.
I also read how it was bind to python, however, the python binding is manually written not generated.
Which means I will have to read all the source code of dlib python binding to do something similar in AutoIt.
Unfortunatly, I am not motivated enough to do it.

 

17 hours ago, malcev said:

tps://google.github.io/mediapipe/

Mediapipe + OpenCv will give us interesting opportunities with advanced copmuter vision.

I have not looked at the source code of mediapipe.
If the python binding is also manually written, it will be a problem similar to dlib.

In conclusion, the idea is still in my mind, but I am not motivated enough to spend time on it.

Edited by smbape
Link to post
Share on other sites
  • 3 weeks later...

Hello, I wrote an issue/question in you're github repo. You maybe still haven't a chance to check. Just to make sure You did not miss it.

 

Saludos

Link to post
Share on other sites
Posted (edited)

Hello @Danyfirex , please post questions on the forum. By doing so, you will increase your chances of having an answer.

@malcev is right, the first argument needs to be an array.

There is an issue in the generated documentation. An up to date documenation is available here.
If you have any other issue, please first check the official documentation of the functions, it may give you the answer. For example hconcat

Local $m1 = _OpenCV_ObjCreate("cv.Mat").zeros(_OpenCV_Size(50, 50), $CV_8UC4)
$m1 = $cv.add($m1, _OpenCV_Scalar(0, 255, 0))
Local $m2 = _OpenCV_ObjCreate("cv.Mat").zeros(_OpenCV_Size(50, 50), $CV_8UC4)
$m2 = $cv.add($m2, _OpenCV_Scalar(255, 0, 0))
Local $contact=$cv.hconcat(_OpenCV_Tuple($m1,$m2))

 

Edited by smbape
Link to post
Share on other sites

@malcev I like to use github haha.

@smbape thank you It works correctly.

 

Saludos

Edited by Danyfirex
Link to post
Share on other sites
  • 1 month later...

Hello Guys,

I don't know if it's appropriate to ask it here : but I can't figure out how to install this UDF :(

I downloaded autoit-opencv-4.5.5-com-v2.0.1 and extract it, and installed the opencv-4.5.5-vc14_vc15.exe.

I tried to run multiple examples that I found on the forum or the GitHub, but I always have this error

!>Error: unable to load 
!>Error: DllInstall: unable to use the DLL file
!>Error: DllInstall -1

I checked the path of the includes, and they are ok, so I'm a bit lost 😅

Can someone explain me how to install it properly ?

Thank you :) 

 

Link to post
Share on other sites
17 hours ago, smbape said:

Hi @iZo

Can you follow these running examples instructions  and give a feedback?

Hi smbape,

So here is what I did :

- I downloaded 7 zip and add it to environment variable ("7z" command is available in cmd)

- I downloaded Git Bash, and executed the code from "Running examples" (after changing directory with a "CD "MyPath"")

To me everything has been running fine (no error), but how can I check if it worked ? (all files seems to have been extracted correctly)

I tried to run au.3 scripts (don't know if it's a stupid idea or not 😅)  "samples\tutorial_code\core\AddingImages\AddingImages.au3" as example. But still have the same error "unable to use the DLL file" 🤔

Link to post
Share on other sites

Hi @iZo

Just be sure, is your directory structure:
My Path
   ---> autoit-addon
   ---> autoit-opencv-com
   ---> opencv-4.5.5-vc14_vc15
   ---> samples

Can you open the file in SciTe editor an run it from there?
Instead of "Run Script", can you use "Run Script (x64)" ?

Link to post
Share on other sites
17 minutes ago, smbape said:

Hi @iZo

Just be sure, is your directory structure:
My Path
   ---> autoit-addon
   ---> autoit-opencv-com
   ---> opencv-4.5.5-vc14_vc15
   ---> samples

Can you open the file in SciTe editor an run it from there?
Instead of "Run Script", can you use "Run Script (x64)" ?

Yes, it's working! I'm sure it's a noob question, but do you know how I can change default settings to always run as x64?

edit : after a bit of research I found I needed to download a second .exe for Scite, in order to make the line "#AutoIt3Wrapper_UseX64=y" working :)

Thanks a lot for your help 😁

Edited by iZo
Link to post
Share on other sites
23 hours ago, smbape said:

To make the context menu "Run Script" to run as x64, edit the registry key HKEY_CLASSES_ROOT\AutoIt3Script\Shell\Run\Command and change AutoIt3.exe to AutoIt3_x64.exe

I just did it! Thanks you for the tips and for the help, I appreciate 😇👍

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