I took it upon myself I meant I wanted to test this too (not that I really know what I'm doing
, just enough to be dangerous I guess). I was about to give up when I suddenly got a result. It has trouble getting a recognition when the (android) tablet is in (or rotated to) landscape mode, but that's probably just me not knowing how to scale sprites / images when rotating it (aspect ratio was wrong too). Even if I rotated it back to portrait, it wouldn't find the QR code (at least not in my few tests now). If someone can improve this feel free to post, ofc
But if I started broadcasting while holding it in portrait mode, and decoding QR while still in portrait mode, it seems to work pretty well!
I figured the solution to your inquiry was somewhere between your example code, and the documentation example for
SetDeviceCameraToImage
Here is a page to
generate QR codes to test with.
The frame rate is not very good, very likely from trying to recognize every frame with this method.
// Project: DecodeQRCode live test
// Created: 2017-07-10
SetDisplayAspect( 1.0 / 1.0 )
setvirtualresolution(100,100)
SetResolutionMode( 1 )
SetSyncRate( 10, 0 )
SetOrientationAllowed( 1,1,1,1 )
setclearcolor(128,128,128)
global qrtext$
qrtext$="hello my facebook friends :-)"
global qrimage
qrimage=encodeqrcode(qrtext$,0)
//saveimage(qrimage,"qr.png")
global qrsprite
qrsprite=createsprite(qrimage)
setspritesize(qrsprite,100,100)
global cam
cam = 0 // usually back-facing camera
get=1
AddVirtualButton( get,5, 5, 10 )
SetVirtualButtonText( get, "Cam" )
SetVirtualButtonColor( get, 64, 64, 192 )
SetVirtualButtonAlpha( get, 192 )
url=2
AddVirtualButton( url,5, 15, 10 )
SetVirtualButtonText( url, "URL" )
SetVirtualButtonColor( url, 64, 64, 192 )
SetVirtualButtonAlpha( url, 192 )
global ende=12
AddVirtualButton( ende,100-5, 5, 10 )
SetVirtualButtonText( ende, "End" )
SetVirtualButtonColor( ende, 64, 64, 192 )
SetVirtualButtonAlpha( ende, 192 )
Text()
do
//Print(qrtext$)
if GetVirtualButtonPressed( get ) then GetCamImage()
if GetVirtualButtonPressed( ende ) then exit
if GetVirtualButtonReleased( url )
if HaveASpace(qrtext$) =0
else
message("a real url have no spaces")
endif
if left(qrtext$,3)="???"
message("i have no url")
else
OpenBrowser(qrtext$)
endif
endif
Sync()
loop
end
function Text()
i=1
if gettextexists(i) then deletetext(i)
CreateText(i,qrtext$)
SetTextPosition(i,getvirtualwidth()/2,0)
SetTextSize(i,3)
SetTextAlignment( i, 1 )
SetTextColor (i,0,0,0 ,255)
endfunction
function GetCamImage()
qrtext$="???"
if GetImageExists(qrimage) then DeleteImage(qrimage)
if getcameraexists()=1
SetDeviceCameraToImage(cam,qrimage) //cam input goto image, image for id will created
if qrsprite then deletesprite(qrsprite)
qrsprite=createsprite(qrimage)
setspritesize(qrsprite,GetVirtualWidth(),GetVirtualHeight())
setspriteposition(qrsprite,0,0)
while qrtext$="???"
qrtext$=decodeqrcode(qrimage)
if len(qrtext$)=0 then qrtext$="???"
Text()
if GetVirtualButtonPressed( ende ) then exit
Sync()
endwhile
SetDeviceCameraToImage(cam, 0) // Stop streaming
else
qrtext$="can't find a cam for get a picture with qr code"
endif
endfunction
function HaveASpace(abc$)
c=0
for i=1 to len(abc$)
if mid(abc$,i,1)=" "
c=c+1
exit
endif
next
endfunction c
EDIT: Clarification and some grammar-ish stuff
Apologies for any typos and strange grammar.