Android OpenCV Camera preview 横屏以及不全屏的问题

CameraBridgeViewBase.java

protected void deliverAndDrawFrame(CvCameraViewFrame frame) {

if (mScale != 0) {
    canvas.drawBitmap(mCacheBitmap, new Rect(0,0,mCacheBitmap.getWidth(), mCacheBitmap.getHeight()),
         new Rect((int)((canvas.getWidth() - mScale*mCacheBitmap.getWidth()) / 2),
         (int)((canvas.getHeight() - mScale*mCacheBitmap.getHeight()) / 2),
         (int)((canvas.getWidth() - mScale*mCacheBitmap.getWidth()) / 2 + mScale*mCacheBitmap.getWidth()),
         (int)((canvas.getHeight() - mScale*mCacheBitmap.getHeight()) / 2 + mScale*mCacheBitmap.getHeight())), null);
} else {
     canvas.drawBitmap(mCacheBitmap, new Rect(0,0,mCacheBitmap.getWidth(), mCacheBitmap.getHeight()),
         new Rect((canvas.getWidth() - mCacheBitmap.getWidth()) / 2,
         (canvas.getHeight() - mCacheBitmap.getHeight()) / 2,
         (canvas.getWidth() - mCacheBitmap.getWidth()) / 2 + mCacheBitmap.getWidth(),
         (canvas.getHeight() - mCacheBitmap.getHeight()) / 2 + mCacheBitmap.getHeight()), null);
}


这样就能全屏了。

canvas.drawBitmap(mCacheBitmap, new Rect(0,0,mCacheBitmap.getWidth(), mCacheBitmap.getHeight()),new Rect(0,0,canvas.getWidth(),canvas.getHeight()), new Paint());
/*


旋转: 

CameraFaceDetectionView.java

    @Override
    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        // 子线程(非UI线程)
        mRgba = inputFrame.rgba();
        mGray = inputFrame.gray();


        Core.transpose(mRgba,mRgbaT); //转置函数,可以水平的图像变为垂直
        Imgproc.resize(mRgbaT,mRgba, mRgba.size(), 0.0D, 0.0D, 0); //将转置后的图像缩放为mRgbaF的大小
        Core.flip(mRgba, mRgba,0); //根据x,y轴翻转,0-x 1-y
//
        Core.transpose(mGray,mRgbaT); //转置函数,可以水平的图像变为垂直
        Imgproc.resize(mRgbaT,mGray, mGray.size(), 0.0D, 0.0D, 0); //将转置后的图像缩放为mRgbaF的大小
        Core.flip(mGray, mGray,0); //根据x,y轴翻转,0-x 1-y

阅读更多

没有更多推荐了,返回首页