问题描述
我想使用OpenCV的2.4.3.2创建一个摄像头应用程序,并做一些OpenCV的处理。我希望它能够有多个UI的方向,不只是风景。
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.
现在的问题是,当我改变方向为纵向,拍摄的图像当中。
The problem is that when I change the orientation to portrait, the image comes out sideways.
据我所知,我做的图像之前可能只是旋转输入图像处理(并且因此离开的取向,因为只有横向),它是精细和工作,但并没有解决问题,即我的UI的其余部分将在错误的方向。
I understand that I could just rotate the input image before doing image processing (and thus leave the orientation as landscape only), which is fine and works, but doesn't solve the problem that the rest of my UI will be in the wrong orientation.
我也尝试过使用这code 旋转摄像头90度,但它只是似乎并没有工作。
I have also tried using this code to rotate the camera 90deg, but it just doesn't seem to work.
mCamera.setDisplayOrientation(90);
它要么没有效果,有的干脆将导致preVIEW被涂黑
It either has no effect, or sometimes just causes the preview to be blacked out
有没有人跟OpenCV的做了这个成功?我的类从JavaCameraView延伸。
Has anyone done this successfully with OpenCV? My class extends from JavaCameraView.
我提出的改进,这是我旋转的图像的OpenCV内,因为它显示在CameraBridgeViewBase.java类
I have made an improvement, which is that I have rotated the image inside of OpenCV as it is displayed in the CameraBridgeViewBase.java class.
在提供和并条机的方法:
In the deliver and draw frame method:
if (canvas != null) {
canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR);
//canvas.drawBitmap(mCacheBitmap, (canvas.getWidth() - mCacheBitmap.getWidth()) / 2, (canvas.getHeight() - mCacheBitmap.getHeight()) / 2, null);
//Change to support portrait view
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, new Paint());
...基本上,这只是roatates输入图像像这样
...Basically, this just roatates the input image like so
这是更好的,但是我当然希望这是全屏显示。
This is better, but I obviously want this to be full screen.
推荐答案
其实,你可以做的宽度或高度数学父(全屏)。
actually,you can just make width or height math parent(full screen).
if (canvas != null) {
canvas.rotate(90,0,0);
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);
...
此外,您还可以使preVIEW尺寸大于screen.Just修改的规模。
Also,you can make the preview size larger than the screen.Just modify the scale.
这篇关于旋转摄像头preVIEW为纵向Android的OpenCV的摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!