使用opencv的android纵向模式的问题 [英] issues in working with android portrait mode with opencv
问题描述
我知道这是最重复的问题之一,但是,经过大量的努力,却找不到任何可行的解决方案.
I know this is one of the most repeated questions, however, no working solution found anywhere, after putting so much of efforts.
尽管对于专家来说可能是一个简单的问题,但这确实是一个致命的问题.
This is really a killing issue though it might be a simple one for the experts.
我正在研究 opencv Haar Cascade 分类器.(例如:面部检测,眼对检测)
I am working on opencv Haar Cascade classifiers.(Eg: Face Detection, Eye Pair Detection)
我刚刚从"OpenCV-2.4.9-android-sdk"-示例中提取了面部检测示例代码.
I have just taken the face-detection sample code from the "OpenCV-2.4.9-android-sdk" - samples.
此示例代码在 Landscape 模式下设置,并且一切正常 fine .
This sample code is set in Landscape mode and everything is working fine.
但是,我想使分类器在人像模式下工作.我知道haar 分类器不是不能用于纵向模式.
However, i want to make make the classifiers work in portrait mode. I know the haar classifiers were not made to work with portrait mode.
由于opencv使用" CameraBridgeViewBase ",因此我没有所有控件来播放相机的分辨率并显示 图像重新显示在屏幕上.(预览)
As opencv uses "CameraBridgeViewBase", i don't have all controls to play with the resolution of the camera and displaying the images back on the screen.(preview)
现在,当我将屏幕方向设置为" android:screenOrientation =纵向" 时,图像将被顺时针旋转 90度时钟.
Now, the moment i set the screen orientation as "android:screenOrientation="portrait", the images is rotated 90deg clock wise.
我尝试过什么:
要预览不旋转的人像图像:我通过添加
Matrix matrix = new Matrix();
matrix.preTranslate((canvas.getWidth() - mCacheBitmap.getWidth()) / 2,(canvas.getHeight() - mCacheBitmap.getHeight()) / 2);
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
matrix.postRotate(90f,(canvas.getWidth()) / 2,(canvas.getHeight()) / 2);
canvas.drawBitmap(mCacheBitmap, matrix, null);
要使分类器以纵向模式工作: 我玩过各种排列组合和 transpose 和 flip 的组合,以旋转传递给我的灰度图像,以检测"onCameraFrame"中的多比例.
To make the classifier work with portrait mode: I played with all kinds of permutation and combination of transpose and flip to rotate the grey scale image that i pass to detectmultiscale in "onCameraFrame".
我的问题是什么?
-
我无法获得具有比"onCameraFrame"更高的原始分辨率的图像. 如何使图像的原始或实际或原始质量达到相机传感器的容量?
I am not able to get the images with native resolution which is higher than what i get at "onCameraFrame". How to get the original or actual or native quality of the images upto the camera sensors capacity?
由于我已经为使分类器在纵向模式下工作而付出了很多努力,因此任何可行的建议/示例代码/参考都将为我提供很多帮助.
推荐答案
我找到了解决方案:
Matrix matrix = new Matrix();
matrix.preTranslate((canvas.getWidth() - mCacheBitmap.getWidth()) / 2,(canvas.getHeight() - mCacheBitmap.getHeight()) / 2);
matrix.postRotate(90f,(canvas.getWidth()) / 2,(canvas.getHeight()) / 2);
float scale = (float) canvas.getWidth() / (float) mCacheBitmap.getHeight();
matrix.postScale(scale, scale, canvas.getWidth()/2 , canvas.getHeight()/2 );
canvas.drawBitmap(mCacheBitmap, matrix, new Paint());
这提供了具有正确比例的人像模式:D请尝试一下.我正在使用OpenCV 3.4.
This delivers portrait mode with CORRECT scale :D try it please. I'm using OpenCV 3.4 .
这篇关于使用opencv的android纵向模式的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!