Rotate camera preview to Portrait Android OpenCV Camera

前端 未结 17 1612
日久生厌
日久生厌 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:14

    It seems like the new OpenCV CameraBridgeViewBase.java class is too high-level and doesn't give enough control over the layout of the camera preview. Take a look at my sample code, which is based on some of the older OpenCV samples and uses pure Android code. To use the byte array passed in onPreviewFrame, put() it into a Mat and convert from YUV to RGB:

    mYuv = new Mat(previewHeight + previewHeight/2, previewWidth, CvType.CV_8UC1);
    mYuv.put(0, 0, mBuffer);
    Imgproc.cvtColor(mYuv, mRgba, Imgproc.COLOR_YUV420sp2RGBA, 4);
    

    You may be able to find the old OpenCV4Android samples on the internet, though they were taken out a few versions ago. However, the linked sample code and the snippet above should be enough to get you started.

提交回复
热议问题