본문 바로가기

Mobile_Programing/Android

Zxing을 세로모드를 인식률 높게 사용해보자.

CameraManager.java에 보면 getFramingRectInPreview()와 getFramingRect()라는 함수가 있습니다
이 두함수는 각각
getFramingRect()
-액티비티화면안에 QR을 인식할 사각영역을 설정
getFramingRectInPreview()
-카메라 프리뷰에서 인식할 사각영역을 설정

그렇기 때문에 getFramingRect()에서 화면에 인식할 영역범위를 지정한 후
getFramingRectInPreview()에서 영역범위와의 사이즈를 맞춰주는것이다.

Zxing은 가로전용모드로 설계가 되어있었기 때문에 세로모드로 하면 인식률이 엄청나게 떨어지는 것을 볼 수 있다.
이는 실제로 화면은 세로 영역인데 , 카메라 프리뷰는 가로 영역을 나타내고있어서 생기는 현상이다
그래서 수동적으로 카메라 프리뷰의 가로 영역을 스와핑해주어야한다.

그러기 위해서,

 public Rect getFramingRectInPreview() {
    if (framingRectInPreview == null) {
      Rect rect = new Rect(getFramingRect());
      Point cameraResolution = configManager.getCameraResolution();
      Point screenResolution = configManager.getScreenResolution();
      rect.left = rect.left * cameraResolution.y / screenResolution.x;
      rect.right = rect.right * cameraResolution.y / screenResolution.x;
      rect.top = rect.top * cameraResolution.x / screenResolution.y;
      rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;
     
      framingRectInPreview = rect;
    }
    return framingRectInPreview;
  }

cameraResolution 부분의 x축과 y축을 변경해주면 된다.