我设法绘制了一个覆盖矩形,以便矩形内的内容是唯一要处理的矩形,应用程序应该忽略其余的相机区域.link to Screenshot
问题是我想在onimagaavailable函数上裁剪上面的矩形,如下所示:
@OverrIDe public voID onImageAvailable(ImageReader reader) { Image img = reader.acquireLatestimage(); //THIS IS WHERE I WANT TO CROP THE IMAGE TO ONLY SHOW WHAT WAS IN THE // ABOVE DRAWN RECTANGLE BUT I DONT KNow HOW, I HAVE GoogleD FOR THE // PAST WEEK ON THIS //after processing i should pass the image to my opencv processing //algorithm process(img) }
这是我在camera2顶部绘制矩形叠加层的代码
@OverrIDe protected voID onDraw(Canvas canvas) { // OverrIDe the onDraw() Method super.onDraw(canvas); paint.setStyle(Paint.Style.stroke); paint.setcolor(color.WHITE); paint.setstrokeWIDth(10); int wIDth = canvas.getWIDth() / 2; int height = canvas.getHeight() / 4; int height1 = canvas.getHeight() / 3; int height_1 = canvas.getHeight() / 10; int fin = canvas.getWIDth() + canvas.getWIDth() / 3; int top = height / 4; Log.e("top", top + ""); canvas.drawRect(canvas.getWIDth() - (canvas.getWIDth() - 150), canvas.getHeight() - fin, canvas.getWIDth() - 150, height + top, paint);}
请帮助/告诉我可以使用哪些代码从ImageReader图像中裁剪矩形,以便将裁剪后的图像传递给我的处理算法
解决方法:
在onImageAvailable()中,您可以使用
Bitmap.createBitmap(如果您已将其转换为JPEG格式)
Rect rectCrop = new Rect(left,top,right,bottom);Bitmap bitmapRotated = Bitmap.createBitmap(bitmap, rectCrop.left, rectCrop.top, rectCrop.wIDth(), rectCrop.height(), mat, true);
如果您使用YUV,则可以减少内存,并使用带有矩形的compresstoJpeg,此过程更加轻松
yuv.compresstoJpeg(rect, compress, out);
总结 以上是内存溢出为你收集整理的android-在camera2上裁剪矩形子部分,并将其传递给opencv进行处理全部内容,希望文章能够帮你解决android-在camera2上裁剪矩形子部分,并将其传递给opencv进行处理所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)