如何检查图像是否变形

时间:2016-10-27 08:20:11

标签: opencv image-processing object-detection opencv4android

我正在使用OpenCV4Android版本2.4.11。我试图改变从相机检索到的帧中检测到的任何矩形形状的预期。有时,当我改变检测到的矩形物体的预测时,我会得到如下所示的变形/不完整图像。

下面发布的代码是为了说明我如何更改被检测对象的预期。

有没有办法用opeCV检查图像是否变形/不完整?因为如果图像变形/不完整,我就不会显示它。

请告诉我怎么做。

 MatOfPoint2f src2f = new MatOfPoint2f();
 MatOfPoint2f dst2f = new MatOfPoint2f();

                    src2f.fromArray(new Point(pointsBoundingRect.x, pointsBoundingRect.y), new Point(pointsBoundingRect.x, pointsBoundingRect.y + pointsBoundingRect.height),
                            new Point(pointsBoundingRect.x + pointsBoundingRect.width, pointsBoundingRect.y + pointsBoundingRect.height), new Point(pointsBoundingRect.x + pointsBoundingRect.width, pointsBoundingRect.y));
                    dst2f.fromArray(new Point(0, 0), new Point(0, 0 + mMatInputFrame.height()),
                            new Point(0 + mMatInputFrame.width(), 0 + mMatInputFrame.height()), new Point(0 + mMatInputFrame.width(), 0));

                    Mat transmtx = Imgproc.getPerspectiveTransform(src2f, dst2f);
                    Mat rotated = new Mat();
                    Imgproc.warpPerspective(mMatInputFrame, rotated, transmtx, mMatInputFrame.size(), Imgproc.INTER_LINEAR, Imgproc.BORDER_REFLECT, new Scalar(255, 255, 255));

                    if (rotated.width() > rotated.height()) {
                        Bitmap bitmap = Bitmap.createBitmap(rotated.cols(), rotated.rows(), Bitmap.Config.ARGB_8888);
                        Utils.matToBitmap(rotated, bitmap);
                        final Bitmap finalBitmap = bitmap;
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                mIVCapture.setImageBitmap(finalBitmap);
                            }
                        });
                    }

图片

enter image description here

更新

设置更大的目标尺寸后,将边框类型设置为BORDER_CONSTANT后,我得到以下结果。请在图像中实现水平条纹

enter image description here

0 个答案:

没有答案