saumitrabhave / qr-zbar-ane

ANE for QR Code Reader
MIT License
84 stars 23 forks source link

Incorrect Camera Rotation #63

Open new-username opened 8 years ago

new-username commented 8 years ago

Hi, I am trying to follow the examples and am able to launch the scanner. Everything works so far however the camera preview is rotated to the left? How would I correct this?

I have also tried using s.setCameraOrientation(degrees) with 0,90,180,270 as the degrees but it is always left rotated.

s = new Scanner(); s.setConfig(Symbology.EAN13,Config.ENABLE,1); s.addEventListener(ScannerEvent.SCAN,onScan); s.startPreview("rear"); s.attachScannerToPreview();

Any help would be appreciated.

Note: Tested on Android Only. (Samsung Galaxy S3 - Android Version 4.3)

mrfrasier commented 8 years ago

I never got it to work consistently across all android devices, so now I just use the Camera object of AS3 and pass the bitmap to the scanner

new-username commented 8 years ago

Doesn't the Camera object have the same problems with orientation? I have run into this problem in the past. I used the old scanner before the updated version and it worked correctly.

I have managed to rotate the preview. Just needed to add s.setCameraOrientation(90) after starting the preview. However now the live preview is stretched.

mrfrasier commented 8 years ago

I haven't had an issue with the normal camera object.

new-username commented 8 years ago

Could you provide a small sample of how you are implementing the code?

new-username commented 8 years ago

After doing multiple tests I seem to have come up with a solution. Could you test this on other Android devices as I am currently limited to one.

s = new Scanner();
s.setConfig(Symbology.EAN13,Config.ENABLE,1);
s.addEventListener(ScannerEvent.SCAN,onScan);
s.addEventListener(ScannerEvent.PREVIEW_TOUCH,destroy);

var h:int;
var w:int;
var degrees:int=0;
var currentCam:String = "rear";
var camRot: int = s.getCameraOrientation(currentCam);
var stageOrientation:String = stage.deviceOrientation;

var vid:Video = new Video();
var vidW:int = vid.width;
var vidH:int = vid.height;

switch(stageOrientation){
    case StageOrientation.DEFAULT:
        degrees = 0;
        break;
    case StageOrientation.ROTATED_LEFT:
        degrees = 270;
        break;
    case StageOrientation.UPSIDE_DOWN:
        degrees = 180;
        break;
    case StageOrientation.ROTATED_RIGHT:
        degrees = 90;
        break;
}

if( degrees == 0 || degrees == 180 ){
    h = stage.stageHeight;
    w = h / vidW * vidH;
}else{
    w = stage.stageWidth;
    h = w / vidW * vidH;
}

if( camRot == 90 ) degrees += camRot;
if( degrees >= 360 ) degrees = 0;

trace("Orientation is " +stageOrientation);
trace("Camera Rotation is " + camRot);
trace("Setting Camera Orientation: " + degrees);

s.startPreview(currentCam,0,0,w,h);
s.attachScannerToPreview();
s.setCameraOrientation(degrees);
saumitrabhave commented 8 years ago

Hi,

I have a test written for this, you can find it at https://github.com/saumitrabhave/qr-zbar-ane/blob/master/Example/src/com/sbhave/reader/tests/PreviewOrientation.as . Is this not working for you ? Can you share your device and android version.

new-username commented 8 years ago

I have already tried to use that example without any luck. The other user (mrfrasier) has also stated that he has "never got it to work consistently across all android devices".

The code I wrote above is based off the example you provided. It worked in portrait however in landscape the image was upside down. This has cause me to modify the code as provided. I am not 100% sure but the key seems to be...

if( camRot == 90 ) degrees += camRot;
if( degrees >= 360 ) degrees = 0;

Samsung Galaxy S3 - Android Version 4.3