Here is the AppGameKit draft (very draft) code and is subject to change. var names are long for easy to read/understand for any beginners out there. A lot to do when I get time. I've also played around with the ResizeImage command to save out binary image files in different sizes. Got an interesting result with GS image when setting bit depth to something like 16. As a data scientist in the clinical trial world, this is right up my alley a bit of stats programming type stuff to do yet.
// Project: OCR_Image2Text
// Created: 21-07-22
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "OCR_Image2Text" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
// maximum greyscale colour value
mxcol=255
// threshold percent
thperc = 75 // e.g. 80%
// threshold calculation
th = mxcol - ((thperc*mxcol) / 100)
src$="BCCI-Stadium-Jersey.jpg"
// load in an image file
original_image_id=loadimage(src$)
// resize image
//ResizeImage(original_image_id,450,450)
// make a memblock from the image file
original_image_memblock_id=creatememblockfromimage(original_image_id)
original_memblock_size=getmemblocksize(original_image_memblock_id)
// make a memblock to hold greyscale image data
greyscale_image_memblock_id=creatememblockfromimage(original_image_id)
infileid=opentowrite("temp_image_dump.txt")
`infileid=opentowrite("raw:c:/temp/temp_image_dump.txt")
w=Getmemblockint(original_image_memblock_id,0)
h=Getmemblockint(original_image_memblock_id,4)
d=Getmemblockint(original_image_memblock_id,8)
writeline(infileid,"width: "+str(w))
writeline(infileid,"height: "+str(h))
writeline(infileid,"depth: "+str(d))
for y=0 to h-1
for x = 0 to w-1
col=GetColour(original_image_memblock_id,x,y)
r=GetColorRed(col)
g=GetColorGreen(col)
b=GetColorBlue(col)
gs=r/3+g/3+b/3
SetColour(greyscale_image_memblock_id,x,y,makecolor(gs,gs,gs))
if gs<th
gs=1
else
if gs>=th
gs=0
endif
endif
out$=out$+str(gs)
next x
writeline (infileid,out$)
out$=""
next y
closefile(infileid)
gsimageid=createimagefrommemblock(greyscale_image_memblock_id)
saveimage(gsimageid,"gs_image.jpg")
`ResizeImage(gsimageid,250,250)
`saveimage(gsimageid,"gs_image250x250.jpg")
do
Print( ScreenFPS() )
Sync()
loop
function GetColour(mem, x , y )
dwWidth = getmemblockint(mem, 0)
offset = 12 + (((dwWidth * y) + x) * 4)
colour = getmemblockint(mem, offset)
endfunction colour
function SetColour(mem, x, y, col)
dwWidth = getmemblockint(mem, 0)
offset = 12 + (((dwWidth * y) + x) * 4) // Each pixel is assumed to be represented by 4 bytes, as is the case most of the time (depth = 32)
setmemblockint (mem, offset, col)
endfunction
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others