Rotate camera preview to Portrait Android OpenCV Camera -
i trying utilize opencv 2.4.3.2 create photographic camera app , opencv processing. able have multiple ui orientations, not landscape.
the problem when alter orientation portrait, image comes out sideways.
i understand i rotate input image before doing image processing (and leave orientation landscape only), fine , works, doesn't solve problem rest of ui in wrong orientation.
i have tried using this code rotate photographic camera 90deg, doesn't seem work.
mcamera.setdisplayorientation(90);
it either has no effect, or causes preview blacked out
has done opencv? class extends javacameraview.
editi have made improvement, have rotated image within of opencv displayed in camerabridgeviewbase.java class.
in deliver , 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 back upwards 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());
... basically, roatates input image so
this better, want total screen.
actually,you can create 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);
...
also,you can create preview size larger screen.just modify scale.
android opencv android-camera
No comments:
Post a Comment