I found a very nice library: Image Recognition Library (https://www.3delite.hu/Object%20Pascal% ... d.html#irl)
Features:
Image Recognition Library is a component for use in Win32 and Win64 (Windows XP/Vista/7/8/10) software with a purpose to provide image recognition functionality, that is compare two pictures if they are the same or similar or find a smaller picture in a bigger picture with difference tolerance.
Requirements: any dev. environment that supports the stdcall calling convention.
- Exact, relative ARGB and AHSL, rotate and 'stretch'" search modes with alpha channel support
- Pre-process images with 6 different resamplers
- Multi-threaded processing
- Multiple match support
- OpenCL accelerated search option
- A fully multi-threaded loading queue functionality for batch loading of pictures
- A fully multi-threaded search queue functionality for batch processing with support of parallel CPU-OpenCL processing a the same time
- Full unicode support
- Platforms: Win32 and Win64
- Delphi and C++ API included
And I am writing code to call this library.
The simplest example of how to use this library consists of 3 steps:
1/ ImageRecognition_CreateObject
2/ ImageRecognition_Compare
3/ ImageRecognition_FreeObject
Step 1 and step 3 I have done, but in step 2, when running the program, the program encounters an error and crashes.
I have tried many ways but still can't fix it. Now I ask everyone to help me fix this error.
Here is the code I did:
IRL.pbi
Code: Select all
Enumeration
#IR_OK
#IR_ERROR_UNKNOWN
#IR_ERROR_NOT_ENOUGH_MEMORY
#IR_ERROR_LOADING
#IR_ERROR_OBJECT
#IR_ERROR_DIMENSIONS
#IR_ERROR_NOT_AVAILABLE
#IR_ERROR_OCL_NOT_AVAILABLE
#IR_ERROR_OCL_NOT_INITIALIZED
#IR_ERROR_OCL_NO_SEARCH_IN_SET
#IR_ERROR_OCL_NO_SEARCH_FOR_SET
#IR_ERROR_NO_SEARCH_QUEUE_SET
#IR_ERROR_OCL_SET_SEARCH_IN
#IR_ERROR_OCL_SET_SEARCH_FOR
#IR_ERROR_NO_LOAD_QUEUE_SET
EndEnumeration
; Status types
#IR_STATUS_PROGRESS = 1
; Compare type modes
Enumeration
#IR_COMPARE_TYPE_EXACT
#IR_COMPARE_TYPE_RELATIVE_ARGB
#IR_COMPARE_TYPE_RELATIVE_AHSL
#IR_COMPARE_TYPE_RELATIVE_ARGB_ALPHA
#IR_COMPARE_TYPE_RELATIVE_AHSL_ALPHA
EndEnumeration
; Queue modes
Enumeration
#IR_SEARCH_MODE_CPU
#IR_SEARCH_MODE_OPENCL
#IR_SEARCH_MODE_ANY
EndEnumeration
; Queue threads
Enumeration
#IR_THREAD_PRIORITY_IDLE
#IR_THREAD_PRIORITY_LOWEST
#IR_THREAD_PRIORITY_LOWER
#IR_THREAD_PRIORITY_NORMAL
#IR_THREAD_PRIORITY_HIGHER
#IR_THREAD_PRIORITY_HIGHEST
#IR_THREAD_PRIORITY_TIMECRITICAL
EndEnumeration
; Pre-process types
Enumeration
#IR_PROCESS_TYPE_NONE
#IR_PROCESS_TYPE_RESAMPLE
EndEnumeration
; Pre-process resample modes
Enumeration
#IR_RESAMPLER_BOX ; // Box, pulse, Fourier window, 1st order (constant) b-spline
#IR_RESAMPLER_BICUBIC ; // Mitchell & Netravali's two-param cubic filter
#IR_RESAMPLER_BILINEAR ; // Bilinear filter
#IR_RESAMPLER_BSPLINE ; // 4th order (cubic) b-spline
#IR_RESAMPLER_CATMULLROM ; // Catmull-Rom spline, Overhauser spline
#IR_RESAMPLER_LANCZOS3 ; // Lanczos3 filter
EndEnumeration
Structure TIRDimensions
Width.l
Height.l
EndStructure
Structure TPoint
X.l
Y.l
EndStructure
Structure TGUID
D1.l
D2.w
D3.w
D4.b[8]
EndStructure
Structure TIRObject
Status.l
*FileName
*ImageObject
ID.TGUID
OriginalDimensions.TIRDimensions
ProcessedDimensions.TIRDimensions
*User
EndStructure
Structure TIRCreateObjectParameters
ProcessType.l
Dimensions.TIRDimensions
Resampler.l
EndStructure
;// typedef void (CALLBACK TIRStatusCallback)(double Progress, int StatusType, void *User)
Prototype TIRStatusCallback(Progress.d, StatusType.l, *User)
Structure TIRProcessParameters
CompareType.l
ARGBATolerance.b
ARGBRTolerance.b
ARGBGTolerance.b
ARGBBTolerance.b
AHSLATolerance.d
AHSLHTolerance.d
AHSLSTolerance.d
AHSLLTolerance.d
DifferenceTolerance.l
StretchCompare.l ;BOOL ;//* Stretch compare is experimental And very slow!
MinimalStretchSize.TIRDimensions
MaximalStretchSize.TIRDimensions
StretchResampler.l ;int
MultipleMatches.l ;BOOL
MultiThreadedProcessing.l ;BOOL
MultiThreadCount.l ;int ;//* 0 means all available CPU cores
*StatusCallback.TIRStatusCallback
RotateSearch.l ;BOOL
RotateSearchStartDegrees.f
RotateSearchEndDegrees.f
RotateSearchStepDegrees.f
SearchSorroundingPixels.l ;BOOL
EndStructure
Structure TIRResultMatches
Position.TPoint
Dimensions.TIRDimensions
Angle.f
Difference.l ;int
MatchPercentage.f
EndStructure
Structure TIRResult
Success.l ;BOOL
MatchCount.l
*Matches;.TIRResultMatches
EndStructure
Structure TIROCLDevice
*Instance
PlatformIndex.l
DeviceIndex.l
EndStructure
Structure TIRSearchQueue
*Instance
EndStructure
;// typedef void (CALLBACK TIRSearchQueueMatchCallback)(int Status, void *WorkID, TIRResult CompareResult, void *User);
Prototype TIRSearchQueueMatchCallback(Status.l, *WorkID, CompareResult, *User);
Structure TIRSearchQueueParameters
OCLDevices.TIROCLDevice ; có thể sai vì nó là PIROCLDevice OCLDevices
OCLDeviceCount.l
OCLThreadPriority.l
CPUThreads.l
CPUThreadsPriority.l
ProcessingMode.l
*SearchQueueMatchCallback.TIRSearchQueueMatchCallback
SearchQueueMatchMessageHandle.i ;HWND
SearchQueueMatchMessageID.l
*User
EndStructure
Structure TIRSearchQueueWork
IRObjectSearchIn.TIRObject
IRObjectSearchFor.TIRObject
Parameters.TIRProcessParameters
SearchMode.l
AutoFreeSearchInIRObject.l ;BOOL
AutoFreeSearchForIRObject.l ;BOOL
*WorkID
EndStructure
Structure TIRSearchQueueResult
Status.l
*WorkID
CompareResult.TIRResult
*User
EndStructure
Structure TIRLoadQueue
*Instance
EndStructure
;// typedef void (CALLBACK TIRLoadQueueCallback)(int Status, TIRObject IRObject, void* User);
Prototype TIRLoadQueueCallback(Status.i, IRObject, *User);
Structure TIRLoadQueueParameters
CPUThreads.l
CPUThreadsPriority.l ;int
*LoadQueueCallback.TIRLoadQueueCallback ;// TIRLoadQueueCallback *LoadQueueCallback;
LoadQueueMessageHandle.i ; HWND
LoadQueueMessageID.l
*User
EndStructure
Code: Select all
IncludeFile "IRL.pbi"
Global IRL = OpenLibrary(#PB_Any, "ImageRecognition.dll")
If IRL = 0
MessageRequester("Fatal Error", "Could not load ImageRecognition.dll")
End
EndIf
;int t_ImageRecognition_CreateObject(LPWSTR FileName, TIRObject *IRObject, TIRCreateObjectParameters Parameters);
PrototypeC t_ImageRecognition_CreateObject(FileName.p-unicode, *IRObject, Parameters)
Global ImageRecognition_CreateObject.t_ImageRecognition_CreateObject = GetFunction(IRL, "ImageRecognition_CreateObject")
IRObjectSearch_In.TIRObject
Parameters_In.TIRCreateObjectParameters
Parameters_In\ProcessType = 0
ImageRecognition_CreateObject("SearchIn.bmp", IRObjectSearch_In, Parameters_In)
Debug PeekS(IRObjectSearch_In\FileName) + " / ImageObj:$" + Hex(IRObjectSearch_In\ImageObject) + " / W:" + Str(IRObjectSearch_In\OriginalDimensions\Width) + " / H:" + Str(IRObjectSearch_In\OriginalDimensions\Height)
IRObjectSearch_For.TIRObject
Parameters_For.TIRCreateObjectParameters
Parameters_For\ProcessType = 0
ImageRecognition_CreateObject("SearchFor.bmp", IRObjectSearch_For, Parameters_For)
Debug PeekS(IRObjectSearch_For\FileName) + " / ImageObj:$" + Hex(IRObjectSearch_For\ImageObject) + " / W:" + Str(IRObjectSearch_For\OriginalDimensions\Width) + " / H:" + Str(IRObjectSearch_For\OriginalDimensions\Height)
;typedef void (CALLBACK TIRStatusCallback)(double Progress, int StatusType, void *User);
Procedure TIRStatusCallback(Progress.d, StatusType.l, *User)
EndProcedure
Parameters.TIRProcessParameters
Parameters\CompareType = #IR_COMPARE_TYPE_EXACT
Parameters\MultipleMatches = #True
TolerancePercent = 1 ; 0 - 99
Parameters\DifferenceTolerance = Int(IRObjectSearch_For\OriginalDimensions\Width * IRObjectSearch_For\OriginalDimensions\Height * (TolerancePercent / 100))
;Parameters\StatusCallback = @TIRStatusCallback( )
CompareResult.TIRResult
;int t_ImageRecognition_Compare(TIRObject IRObjectSearchIn, TIRObject IRObjectSearchFor, TIRProcessParameters Parameters, TIRResult *CompareResult, void *User);
PrototypeC t_ImageRecognition_Compare(IRObjectSearchIn, IRObjectSearchFor, Parameters, *CompareResult, *User)
Global ImageRecognition_Compare.t_ImageRecognition_Compare = GetFunction(IRL, "ImageRecognition_Compare")
ImageRecognition_Compare(IRObjectSearch_In, IRObjectSearch_For, Parameters, CompareResult, 0)
;=> Error and crashs
;int t_ImageRecognition_FreeObject(TIRObject *IRObject);
PrototypeC t_ImageRecognition_FreeObject(IRObject)
Global ImageRecognition_FreeObject.t_ImageRecognition_FreeObject = GetFunction(IRL, "ImageRecognition_FreeObject")
ImageRecognition_FreeObject(IRObjectSearch_In)
ZeroMemory_(IRObjectSearch_In, SizeOf(IRObjectSearch_In))
Debug "O:$" + Hex(IRObjectSearch_In\ImageObject) + " / W:" + Str(IRObjectSearch_In\OriginalDimensions\Width) + " / H:" + Str(IRObjectSearch_In\OriginalDimensions\Height)
ImageRecognition_FreeObject(IRObjectSearch_For)
ZeroMemory_(IRObjectSearch_For, SizeOf(IRObjectSearch_For))
Debug "O:$" + Hex(IRObjectSearch_For\ImageObject) + " / W:" + Str(IRObjectSearch_For\OriginalDimensions\Width) + " / H:" + Str(IRObjectSearch_For\OriginalDimensions\Height)
ZeroMemory_(Parameters_In, SizeOf(Parameters_In))
ZeroMemory_(Parameters_For, SizeOf(Parameters_For))
- Exe tutorial with source code of Image Recognition Library: https://www.3delite.hu/Object%20Pascal% ... d.html#irl
- My work (includes: my Pb scripts, dll, images ): https://1drv.ms/u/s!AhiIbjk1VKtOdddM89QC42h6_Cc