Rotate camera preview to Portrait Android OpenCV Camera

前端 未结 17 1592
日久生厌
日久生厌 2020-12-07 15:45

I am trying to use OpenCV 2.4.3.2 to create a camera app and do some opencv processing. I would like it to be able to have multiple UI orientations, not just Landscape.

17条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 16:27

    Actually, you can just make width or height match parent (full screen).

    if (canvas != null) {
            Bitmap bitmap = Bitmap.createScaledBitmap(mCacheBitmap, canvas.getHeight(), canvas.getWidth(), true);
            canvas.rotate(90,0,0);
            float scale = canvas.getWidth() / (float)bitmap.getHeight();
            float scale2 = canvas.getHeight() / (float)bitmap.getWidth();
            if(scale2 > scale){
                scale = scale2;
            }
            if (scale != 0) {
                canvas.scale(scale, scale,0,0);
            }
            canvas.drawBitmap(bitmap, 0, -bitmap.getHeight(), null);
    

    ...

    Also, you can make the preview size larger than the screen. Just modify the scale.

提交回复
热议问题