Page 3 of 3

Re: Windows 10 OCR and Face detection

Posted: Mon Feb 14, 2022 8:07 am
by dige
@fryquez: Thank you very much for that. This could be very useful.

Re: Windows 10 OCR and Face detection

Posted: Tue Apr 05, 2022 10:30 am
by XCoder
I have updated the code in my earlier post for OCRing text on the screen so that it works correctly with x64 versions of Windows. The updated code may be downloaded by clicking the download link in my original post.

Re: Windows 10 OCR and Face detection

Posted: Tue Apr 05, 2022 11:59 am
by acreis
Thank you very much!

Re: Windows 10 OCR and Face detection

Posted: Sat Aug 06, 2022 6:25 pm
by gally
Hello,

A small question: is it possible to adapt the code to do handwriting detection?

Thanks in advance,
Cordially,

Re: Windows 10 OCR and Face detection

Posted: Tue Aug 30, 2022 4:23 pm
by AZJIO

Code: Select all

EnableExplicit

XIncludeFile "Windows 10 OCR and Face detection.pb"

#Win0 = 0
#SysTrayIcon = 0
#Menu = 0
Enumeration
	#mExit
	#mCapture
EndEnumeration

Structure tOCR_DEMO
	ImageID.i
	sFromImage.s
EndStructure


Global tOCR_DEMO.tOCR_DEMO
Global HDC

Define hWnd_0

Procedure OCR_DEMO(*OCR_DEMO.tOCR_DEMO)
	If *OCR_DEMO\ImageID
		*OCR_DEMO\sFromImage = WinOCR::get_TextFromImageID(*OCR_DEMO\ImageID)
	EndIf
EndProcedure

Procedure HBitmapFromScreen(X, Y, W, H)
	Protected HBM, PDC
	If Not HDC
		HDC = GetDC_(0)
	EndIf
	HBM = CreateCompatibleBitmap_(HDC, W, H)
	PDC = CreateCompatibleDC_(HDC)
	SelectObject_(PDC, HBM)
	BitBlt_(PDC, 0, 0, W, H, HDC, X, Y, #SRCCOPY)
	DeleteDC_(PDC)
	ProcedureReturn HBM
EndProcedure


Procedure CaptureText()
	Protected thread
	tOCR_DEMO\ImageID = HBitmapFromScreen(WindowX(#Win0, #PB_Window_InnerCoordinate),
	                                      WindowY(#Win0, #PB_Window_InnerCoordinate),
	                                      WindowWidth(#Win0),
	                                      WindowHeight(#Win0))
	
	thread = CreateThread(@OCR_DEMO(), @tOCR_DEMO)
	If thread
		WaitThread(thread)
		SetClipboardText(tOCR_DEMO\sFromImage)
		MessageRequester("On the clipboard", tOCR_DEMO\sFromImage)
	EndIf
	DeleteObject_(tOCR_DEMO\ImageID)
EndProcedure


Procedure _Exit()
	ReleaseDC_(0, HDC)
	CloseWindow(#Win0)
	RemoveSysTrayIcon(#SysTrayIcon)
	End
EndProcedure


hWnd_0 = OpenWindow(#Win0, 0, 0, 400, 200, "Click in the center of the window", #PB_Window_ScreenCentered | #WS_SIZEBOX | #PB_Window_Tool | #PB_Window_SystemMenu | #PB_Window_Invisible | #WS_BORDER)
If hWnd_0
	SetWindowColor(#Win0, #Blue)
	SetWindowLong_(hWnd_0, #GWL_EXSTYLE, #WS_EX_LAYERED | #WS_EX_TOPMOST)
	SetLayeredWindowAttributes_(hWnd_0, #Blue, 110, #LWA_COLORKEY)
	
	If CreatePopupMenu(#Menu)
		MenuItem(#mCapture, "Text capture")
		MenuBar()
		MenuItem(#mExit, "Exit")
	EndIf
	AddSysTrayIcon(#SysTrayIcon, hWnd_0, GetClassLongPtr_(hWnd_0, #GCL_HICON))
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_LeftClick, #PB_Event_RightClick
				CaptureText()
			Case #PB_Event_CloseWindow
				HideWindow(#Win0, #True)
				StickyWindow(#Win0, #False) 
;- Tray Events
			Case #PB_Event_SysTray
				Select EventType()
					Case #PB_EventType_RightClick, #PB_EventType_LeftClick
						DisplayPopupMenu(#Menu, hWnd_0)
				EndSelect
;- Menu Events
		Case #PB_Event_Menu
			Select EventMenu()
				Case #mExit
					_Exit()
				Case #mCapture
					HideWindow(#Win0, #False)
					StickyWindow(#Win0, #True) 
			EndSelect
		EndSelect
	ForEver
EndIf

Re: Windows 10 OCR and Face detection

Posted: Tue May 30, 2023 2:52 pm
by dige
@fryquez : Thanks again for the WIC image loading function. I use it a lot to load HEIC images.

Unfortunately, there seems to be a memory leak. I can only load 11 images with it, then at

Code: Select all

*hDIBBitmap\i = CreateDIBSection_(hdcScreen, @bminfo, #DIB_RGB_COLORS, @*pvImageBits, #Null, 0)
will no more buffer created. Probably no more free memory?

Does the memory of CreateDIBSection have to be released via DeleteObject?

any help is appreciated!

Kind regards

Dige
fryquez wrote: Sun Nov 14, 2021 6:45 pm

Code: Select all

EnableExplicit

Macro WIC_SUCCEEDED(HRESULT)
  (HRESULT & $80000000 = 0)
EndMacro

#WICBitmapInterpolationModeNearestNeighbor	= 0
#WICBitmapInterpolationModeLinear	= 1
#WICBitmapInterpolationModeCubic	= 2
#WICBitmapInterpolationModeFant	= 3
#WICBitmapInterpolationModeHighQualityCubic	= 4
#WICBITMAPINTERPOLATIONMODE_FORCE_DWORD	= $7fffffff

#WICBitmapTransformRotate0	= 0
#WICBitmapTransformRotate90	= 1
#WICBitmapTransformRotate180	= 2
#WICBitmapTransformRotate270	= 3
#WICBitmapTransformFlipHorizontal	= 8
#WICBitmapTransformFlipVertical	= $10
#WICBITMAPTRANSFORMOPTIONS_FORCE_DWORD	= $7fffffff

Interface IWICMetadataQueryReader Extends IUnknown
  GetContainerFormat(*pguidContainerFormat)
  GetLocation(cchMaxLength, *wzNamespace, *pcchActualLength)
  GetMetadataByName(wzName, *pvarValue)
  GetEnumerator(*ppIEnumString)
EndInterface

Interface IWICComponentInfo Extends IUnknown
  GetComponentType(*pType)
  GetCLSID(*pclsid.CLSID)
  GetSigningStatus(*pStatus)
  GetAuthor(cchAuthor, *wzAuthor, *pcchActual)
  GetVendorGUID(*pguidVendor.GUID)
  GetVersion(cchVersion, *wzVersion, *pcchActual)
  GetSpecVersion(cchSpecVersion, *wzSpecVersion, *pcchActual)
  GetFriendlyName(cchFriendlyName, *wzFriendlyName, *pcchActual)
EndInterface

Interface IWICBitmapCodecInfo Extends IWICComponentInfo
  GetContainerFormat(*pguidContainerFormat.GUID)
  GetPixelFormats(cFormats, *pguidPixelFormats.GUID, *pcActual.l)
  GetColorManagementVersion(cchColorManagementVersion, *wzColorManagementVersion, *pcchActual.l)
  GetDeviceManufacturer(cchDeviceManufacturer, *wzDeviceManufacturer, *pcchActual.l)
  GetDeviceModels(cchDeviceModels, *wzDeviceModels, *pcchActual.l)  
  GetMimeTypes(cchMimeTypes, *wzMimeTypes, *pcchActual.l)
  GetFileExtensions(cchFileExtensions, *wzFileExtensions, *pcchActual.l)  
  DoesSupportAnimation(*pfSupportAnimation.l)
  DoesSupportChromakey(*pfSupportChromakey.l)
  DoesSupportLossless(*pfSupportLossless.l)
  DoesSupportMultiframe(*pfSupportMultiframe.l)  
  MatchesMimeType(wzMimeType, *pfMatches)  
EndInterface

Interface IWICImagingFactory Extends IUnknown
  CreateDecoderFromFilename(wzFilename.p-unicode, *pguidVendor, dwDesiredAccess,  metadataOptions, *ppIDecoder)
  CreateDecoderFromStream(*pIStream, *pguidVendor, metadataOptions, *ppIDecoder)
  CreateDecoderFromFileHandle(hFile, *pguidVendor, metadataOptions, *ppIDecoder)
  CreateComponentInfo(clsidComponent, *ppIInfo)
  CreateDecoder(guidContainerFormat, *pguidVendor, *ppIDecoder)
  CreateEncoder(guidContainerFormat, *pguidVendor, *ppIEncoder)
  CreatePalette(*ppIPalette)
  CreateFormatConverter(*ppIFormatConverter)
  CreateBitmapScaler(*ppIBitmapScaler)
  CreateBitmapClipper(*ppIBitmapClipper)
  CreateBitmapFlipRotator(*ppIBitmapFlipRotator)
  CreateStream(*ppIWICStream)
  CreateColorContext(*ppIWICColorContext)
  CreateColorTransformer(*ppIWICColorTransform)
  CreateBitmap(uiWidth, uiHeight, pixelFormat, option, *ppIBitmap)
  CreateBitmapFromSource(*piBitmapSource, option, *ppIBitmap)
  CreateBitmapFromSourceRect(*piBitmapSource, x, y, width, height, *ppIBitmap)
  CreateBitmapFromMemory(uiWidth, uiHeight, pixelFormat, cbStride, cbBufferSize, *pbBuffer, *ppIBitmap)
  CreateBitmapFromHBITMAP(hBitmap, hPalette, options, *ppIBitmap)
  CreateBitmapFromHICON(hIcon, *ppIBitmap)
  CreateComponentEnumerator(componentTypes, options, *ppIEnumUnknown)
  CreateFastMetadataEncoderFromDecoder(*pIDecoder, *ppIFastEncoder)
  CreateFastMetadataEncoderFromFrameDecode(*pIFrameDecoder, *ppIFastEncoder)
  CreateQueryWriter(guidMetadataFormat, *pguidVendor, *ppIQueryWriter)
  CreateQueryWriterFromReader(*pIQueryReader, *pguidVendor, *ppIQueryWriter)
EndInterface

Interface IWICStream Extends IStream
  InitializeFromIStream(Stream.IStream)
  InitializeFromFilename(*sFilename, AccessMode.l)
  InitializeFromMemory(*Buffer, BufferSize.l)
  InitializeFromIStreamRegion(Stream.IStream, Offset.q, MaxSize.q)
EndInterface

Interface IWICBitmapSource Extends IUnknown
  GetSize(*puiWidth, *puiHeight)
  GetPixelFormat(*pPixelFormat)
  GetResolution(*pDpiX, *pDpiY)
  CopyPalette(*pIPalette)
  CopyPixels(*prc, cbStride, cbBufferSize, *pbBuffer)
EndInterface

Interface IWICBitmapFlipRotator Extends IWICBitmapSource
  Initialize(*pISource, options)
EndInterface

Interface IWICBitmap Extends IWICBitmapSource
  Lock(*prcLock, flags, *ppILock)
  SetPalette(*pIPalette)
  SetResolution(dpiX.d, dpiY.d)
EndInterface

Interface IWICFormatConverter Extends IWICBitmapSource
  Initialize(*pISource, dstFormat, dither, *pIPalette, alphaThresholdPercent.d, paletteTranslate)
  CanConvert(srcPixelFormat, dstPixelFormat, *pfCanConvert)
EndInterface

Interface IWICBitmapDecoder Extends IUnknown
  QueryCapability(*pIStream, *pdwCapability)
  Initialize(*pIStream, cacheOptions)
  GetContainerFormat(*pguidContainerFormat)
  GetDecoderInfo(*ppIDecoderInfo)
  CopyPalette(*pIPalette)
  GetMetadataQueryReader(*ppIMetadataQueryReader)
  GetPreview(*ppIBitmapSource)
  GetColorContexts(cCount, *ppIColorContexts, *pcActualCount)
  GetThumbnail(*ppIThumbnail)
  GetFrameCount(*pCount)
  GetFrame(index, *ppIBitmapFrame)
EndInterface

Interface IWICBitmapFrameDecode Extends IWICBitmapSource
  GetMetadataQueryReader(*ppIMetadataQueryReader)
  GetColorContexts(cCount, *ppIColorContexts, *pcActualCount)
  GetThumbnail(*ppIThumbnail)
EndInterface

Interface IWICBitmapScaler Extends IWICBitmapSource
  Initialize(*pISource, uiWidth, uiHeight, mode)
EndInterface


Macro WIC_DEFINE_GUID(label,l1,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)
  label:
  Data.l l1
  Data.w w1,w2
  Data.b b1,b2,b3,b4,b5,b6,b7,b8
EndMacro


DataSection
  WIC_DEFINE_GUID(CLSID_WICImagingFactory        , $cacaf262,$9370,$4615,$a1,$3b,$9f,$55,$39,$da,$4c,$0a)
  WIC_DEFINE_GUID(IID_IWICImagingFactory         , $ec5ec8a9,$c395,$4314,$9c,$77,$54,$d7,$a9,$35,$ff,$70)
  WIC_DEFINE_GUID(CLSID_WICImagingFactory2       , $317d06e8,$5f24,$433d,$bd,$f7,$79,$ce,$68,$d8,$ab,$c2)
  WIC_DEFINE_GUID(IID_IWICImagingFactory2        , $7B816B45,$1996,$4476,$B1,$32,$DE,$9E,$24,$7C,$8A,$F0)
  WIC_DEFINE_GUID(GUID_ContainerFormatBmp        , $0af1d87e,$fcfe,$4188,$bd,$eb,$a7,$90,$64,$71,$cb,$e3)
  WIC_DEFINE_GUID(GUID_ContainerFormatPng        , $1b7cfaf4,$713f,$473c,$bb,$cd,$61,$37,$42,$5f,$ae,$af)
  WIC_DEFINE_GUID(GUID_ContainerFormatJpeg       , $19e4a5aa,$5662,$4fc5,$a0,$c0,$17,$58,$02,$8e,$10,$57)
  WIC_DEFINE_GUID(GUID_ContainerFormatTiff       , $163bcc30,$e2e9,$4f0b,$96,$1d,$a3,$e9,$fd,$b7,$88,$a3)
  WIC_DEFINE_GUID(GUID_ContainerFormatGif        , $1f8a5601,$7d4d,$4cbd,$9c,$82,$1b,$c8,$d4,$ee,$b9,$a5)
  WIC_DEFINE_GUID(GUID_WICPixelFormat32bppBGR    , $6fddc324,$4e03,$4bfe,$b1,$85,$3d,$77,$76,$8d,$c9,$0e)
  WIC_DEFINE_GUID(GUID_WICPixelFormat32bppPBGRA  , $6fddc324,$4e03,$4bfe,$b1,$85,$3d,$77,$76,$8d,$c9,$10)
  WIC_DEFINE_GUID(IID_IWICPixelFormatInfo        , $E8EDA601,$3D48,$431a,$AB,$44,$69,$05,$9B,$E8,$8B,$BE)
  WIC_DEFINE_GUID(IID_IWICComponentInfo          , $23BC3F0A,$698B,$4357,$88,$6B,$F2,$4D,$50,$67,$13,$34)
  WIC_DEFINE_GUID(IID_IWICBitmapSource           , $00000120,$a8f2,$4877,$ba,$0a,$fd,$2b,$66,$45,$fb,$94)
  
  WIC_DEFINE_GUID(IID_IWICBitmapCodecInfo        , $E87A44C4,$B76E,$4C47,$8B,  9,$29,$8E,$B1,$2A,$27,$14)
  
EndDataSection




Global g__pIWICFactory.IWICImagingFactory

Procedure WIC_Initialize_Factory()
  ProcedureReturn CoCreateInstance_(?CLSID_WICImagingFactory, 0, #CLSCTX_INPROC_SERVER, ?IID_IWICImagingFactory, @g__pIWICFactory)  
EndProcedure



Procedure WIC_CreateDIBSectionFromBitmapSource(*pToRenderBitmapSource.IWICBitmapSource, *hDIBBitmap.Integer, iOriantation = 0)
  
  Protected bminfo.BITMAPINFO
  Protected width, height, cbStride, cbImage, hdcScreen, *pvImageBits
  Protected hr.l = *pToRenderBitmapSource\GetSize(@width, @height)
  
  If (iOriantation & #WICBitmapTransformRotate90) Or (iOriantation & #WICBitmapTransformRotate270)
    cbStride = height
    height = width
    width = cbStride
  EndIf
  
  ZeroMemory_(@bminfo, SizeOf(bminfo))
  bminfo\bmiHeader\biSize         = SizeOf(BITMAPINFOHEADER)
  bminfo\bmiHeader\biWidth        = width                   
  bminfo\bmiHeader\biHeight       = 0 - height
  bminfo\bmiHeader\biPlanes       = 1                       
  bminfo\bmiHeader\biBitCount     = 32                      
  bminfo\bmiHeader\biCompression  = #BI_RGB                  
  
  hdcScreen = GetDC_(0)
  *hDIBBitmap\i = CreateDIBSection_(hdcScreen, @bminfo, #DIB_RGB_COLORS, @*pvImageBits, #Null, 0)
  ReleaseDC_(0, hdcScreen)
  
  cbStride = width * 4
  cbImage = cbStride * height
  
  If iOriantation = 0
    hr = *pToRenderBitmapSource\CopyPixels(#Null, cbStride, cbImage, *pvImageBits)
    If Not WIC_SUCCEEDED(hr)
      DeleteObject_(*hDIBBitmap\i)
      *hDIBBitmap\i = 0
    EndIf
    
    ProcedureReturn hr
  EndIf
  
  Protected *pIFlipRotator.IWICBitmapFlipRotator
  hr = g__pIWICFactory\CreateBitmapFlipRotator(@*pIFlipRotator)            
  If WIC_SUCCEEDED(hr)
    hr = *pIFlipRotator\Initialize(*pToRenderBitmapSource, iOriantation)
    hr = *pIFlipRotator\CopyPixels(#Null, cbStride, cbImage, *pvImageBits)
    If Not WIC_SUCCEEDED(hr)
      DeleteObject_(*hDIBBitmap\i)
      *hDIBBitmap\i = 0
    EndIf
    *pIFlipRotator\Release()
    ProcedureReturn hr
  EndIf
    
EndProcedure



Procedure WIC_CatchImage(*Memory, iSize, *cx.Integer = 0, *cy.Integer = 0, *iFrame.Integer = 0)
  
  Protected *pDecoder.IWICBitmapDecoder
  Protected *pFrame.IWICBitmapFrameDecode
  Protected *pToRenderBitmapSource.IWICBitmapSource
  Protected *pScaler.IWICBitmapScaler
  Protected *pConverter.IWICFormatConverter
  Protected *WICBitmapSrc.IWICBitmapSource
  Protected *IWICStream.IWICStream
  Protected hBitmap, width, height, hr.l, bDoReSize, index
  
  
  If Not g__pIWICFactory Or g__pIWICFactory\CreateStream(@*IWICStream)
    Debug "g__pIWICFactory !"
    ProcedureReturn 0
  EndIf
    
  hr = *IWICStream\InitializeFromMemory(*Memory, iSize)  
  If WIC_SUCCEEDED(hr)
    hr = g__pIWICFactory\CreateDecoderFromStream(*IWICStream, 0, 0, @*pDecoder)    
    If WIC_SUCCEEDED(hr)
      
      If *iFrame
        index = *iFrame\i
      EndIf
      
      hr = *pDecoder\GetFrame(index, @*pFrame)
      If WIC_SUCCEEDED(hr)
        
        If *iFrame And *iFrame\i = 0
          *pDecoder\GetFrameCount(@*iFrame\i)
        EndIf
        
        Protected *pQueryReader.IWICMetadataQueryReader
        hr = *pFrame\GetMetadataQueryReader(@*pQueryReader)
        If WIC_SUCCEEDED(hr)          
          Protected bitmapTransformationOptions, VariantMetaData.VARIANT
          hr = *pQueryReader\GetMetadataByName(@"/app1/{ushort=0}/{ushort=274}", @VariantMetaData)
          If WIC_SUCCEEDED(hr)
            Select VariantMetaData\iVal
              Case 2
                bitmapTransformationOptions = #WICBitmapTransformRotate0 | #WICBitmapTransformFlipHorizontal
              Case 3
                bitmapTransformationOptions = #WICBitmapTransformRotate180
              Case 4
                bitmapTransformationOptions = #WICBitmapTransformRotate180 | #WICBitmapTransformFlipHorizontal
              Case 5
                bitmapTransformationOptions = #WICBitmapTransformRotate270 | #WICBitmapTransformFlipHorizontal
              Case 6
                bitmapTransformationOptions = #WICBitmapTransformRotate90
              Case 7
                bitmapTransformationOptions = #WICBitmapTransformRotate90 | #WICBitmapTransformFlipHorizontal
              Case 8
                bitmapTransformationOptions = #WICBitmapTransformRotate270
            EndSelect            
          EndIf          
          *pQueryReader\Release()
        EndIf
        
        hr = *pFrame\QueryInterface(?IID_IWICBitmapSource, @*WICBitmapSrc)
        If WIC_SUCCEEDED(hr)
          
          hr = *WICBitmapSrc\GetSize(@width, @height)
          hr = g__pIWICFactory\CreateBitmapScaler(@*pScaler)
          
          If WIC_SUCCEEDED(hr)
            
            If *cx And *cx\i
              width = *cx\i
              bDoReSize = #True
            EndIf
            
            If *cy And *cy\i
              height = *cy\i
              bDoReSize = #True
            EndIf
            
            If (bitmapTransformationOptions & #WICBitmapTransformRotate90) Or (bitmapTransformationOptions & #WICBitmapTransformRotate270)
              hr = height
              height = width
              width = hr
            EndIf
            
            
            
            hr = *pScaler\Initialize(*WICBitmapSrc, width, height, #WICBitmapInterpolationModeFant)
            If WIC_SUCCEEDED(hr)
              g__pIWICFactory\CreateFormatConverter(@*pConverter);
              If WIC_SUCCEEDED(hr)
                hr = *pConverter\Initialize(*pScaler, ?GUID_WICPixelFormat32bppBGR, 0, #Null, 0.0, 0)
                If WIC_SUCCEEDED(hr)
                  hr = *pConverter\QueryInterface(?IID_IWICBitmapSource, @*pToRenderBitmapSource)        
                  If WIC_SUCCEEDED(hr)
                    
                    hr = WIC_CreateDIBSectionFromBitmapSource(*pToRenderBitmapSource, @hBitmap, bitmapTransformationOptions)
                    If WIC_SUCCEEDED(hr)
                      If *cx Or *cy
                        *pToRenderBitmapSource\GetSize(@width, @height)
                        
                        If *cx And *cx\i = 0
                          *cx\i = width
                        EndIf
                        
                        If *cy And *cy\i = 0
                          *cy\i = height
                        EndIf
                      EndIf
                    EndIf
                    
                    *pToRenderBitmapSource\Release()
                  EndIf   
                  
                EndIf
              EndIf
            EndIf 
          EndIf
          
          *WICBitmapSrc\Release()
          
        EndIf
        *pFrame\Release()
      EndIf
      
      *pDecoder\Release()
    EndIf
    
    *IWICStream\Release()
  EndIf
  
  ProcedureReturn hBitmap
  
  
EndProcedure



Procedure WIC_LoadImage(sFile.s, *cx.Integer = 0, *cy.Integer = 0, *iFrame.Integer = 0)
  
  Protected hFile, buffer, cbSize, hBitmap
  
  hFile = ReadFile(#PB_Any, sFile)
  If hFile
    cbSize = Lof(hFile)
    If cbSize
      buffer = AllocateMemory(cbSize)
      If buffer
        If ReadData(hFile, buffer, cbSize)
          hBitmap = WIC_CatchImage(buffer, cbSize, *cx, *cy, *iFrame)
        EndIf
        FreeMemory(buffer)
      EndIf
    EndIf
    CloseFile(hFile)
  EndIf
  
  ProcedureReturn hBitmap
  
EndProcedure




Procedure WIC_Enum_Decoders()
  
  Protected hr.l, spEnum.IEnumUnknown, spEnumElement.IWICComponentInfo, cbActual
  Protected sName.s{261}, sExtentions.s{261}
  Protected IWICBitmapCodecInfo.IWICBitmapCodecInfo
  
  If Not g__pIWICFactory
    Debug "g__pIWICFactory !"
    ProcedureReturn 0
  EndIf
  
  hr = g__pIWICFactory\CreateComponentEnumerator(1, 0, @spEnum)
  If SUCCEEDED_(hr)
    
    While (#S_OK = spEnum\Next(1, @spEnumElement, @cbActual))
      
      hr = spEnumElement\QueryInterface(?IID_IWICBitmapCodecInfo, @IWICBitmapCodecInfo)
      If SUCCEEDED_(hr)
        IWICBitmapCodecInfo\GetFriendlyName(260, @sName, @cbActual)
        Debug sName
        IWICBitmapCodecInfo\GetFileExtensions(260, @sExtentions, @cbActual)
        Debug #TAB$ + sExtentions + #CRLF$        
        IWICBitmapCodecInfo\Release()
      EndIf
      
      spEnumElement\Release()
    Wend
    
    spEnum\Release()
  EndIf
  
EndProcedure



;- example

CompilerIf #PB_Compiler_IsMainFile
  
  
  CoInitialize_(0)
  WIC_Initialize_Factory()
  ;WIC_Enum_Decoders()
  
  
  Define cx = 800, cy = 600, iFrame, sFile.s, hBitmap
  
  sFile = OpenFileRequester("Images files", "", "All files (*.*)|*.*", 0)
  If sFile <> ""
    hBitmap = WIC_LoadImage(sFile, @cx, @cy, @iFrame)
    If Not hBitmap
      Debug "Error loading " + sFile
    Else
      If OpenWindow(0, 0, 0, 800, 600, "WIC Image", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
        ImageGadget(0,  0, 0, 800, 600, hBitmap)
        Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
      EndIf
    EndIf
    
  EndIf
  
CompilerEndIf

Re: Windows 10 OCR and Face detection

Posted: Tue May 30, 2023 6:23 pm
by fryquez
dige wrote: Tue May 30, 2023 2:52 pm Does the memory of CreateDIBSection have to be released via DeleteObject?
Yes, both WIC_CatchImage() and WIC_LoadImage() return a hBitmap. You have to free it with DeleteObject_() API.

But the actual problem was missing release of *pConverter and *pScaler interfaces in WIC_CatchImage.

Re: Windows 10 OCR and Face detection

Posted: Tue May 30, 2023 9:29 pm
by dige
Thx fryquez, good to know. But I really dont know how to fix this. Could you help please?

Re: Windows 10 OCR and Face detection

Posted: Wed May 31, 2023 8:12 am
by fryquez
I have updated the code on page 2.

Re: Windows 10 OCR and Face detection

Posted: Wed May 31, 2023 8:45 am
by dige
¡Muchas gracias! :D

Re: Windows 10 OCR and Face detection

Posted: Sun Feb 18, 2024 11:15 am
by gally
Good Morning,

I'm trying to find the text as well as the position of the text on the page. I saw that this is possible in the official Microsoft documentation, but I can't seem to adapt this.
Can you help understand and adapt this?

Thanks in advance
Gally

Re: Windows 10 OCR and Face detection

Posted: Sun Feb 18, 2024 5:10 pm
by fryquez
I added the pastbin link to first post. This updated version should give you the rectangle of every detected word.

Re: Windows 10 OCR and Face detection

Posted: Mon Feb 19, 2024 9:49 am
by gally
Alors comment dire --> Juste un grand merci ^^
So how can I say --> Just a big thank you ^^

Re: Windows 10 OCR and Face detection

Posted: Fri Jun 14, 2024 12:26 pm
by gally
Good morning,

Thanks again fryquez for all the help. This source is really great and helped me a lot.

---------------------------------------------------------------------------------

Bonjour,

Encore merci fryquez pour toutes l'aides. cette source est vraiment génial et m'a beaucoup aidé.