Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Assertion failed in getAffineTransform

so i am just trying to align this image

here

and i am following these steps here

so after performing hough transform the result was this image

image description

and now i am performing affine Transform and i am getting the Cvtype error

OpenCV Error: Assertion failed (src.checkVector(2, CV_32F) == 3 && dst.checkVector(2, CV_32F) == 3) in getAffineTransform, file /home/tomna/Desktop/opencv-3.1.0/modules/imgproc/src/imgwarp.cpp, line 6360 Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: /home/tomna/Desktop/opencv-3.1.0/modules/imgproc/src/imgwarp.cpp:6360: error: (-215) src.checkVector(2, CV_32F) == 3 && dst.checkVector(2, CV_32F) == 3 in function getAffineTransform

]

here is my code

        System.out.println("Detecting Charachters");
        Mat roi_image = ("122.jpg");
        Mat element = getStructuringElement(MORPH_RECT, new Size(2, 2));
        Mat Kernel = Mat.ones(new Size(1, 1), MORPH_RECT);
        Mat roi_canny = new Mat();
        Mat roi_lines = new Mat();
        Mat roi_bila = new Mat();
        Mat roi_histo = new Mat();
        Mat roi_morphologyEx = new Mat();
        Mat roi_grey = new Mat();

        Mat roi_sobel = new Mat();

        Imgproc.cvtColor(roi_image, roi_image, Imgproc.COLOR_BGR2GRAY);
        Imgproc.equalizeHist(roi_image, roi_histo);

/////////////////edge detection/////////////////////////////////////////////////////////////////
        Imgproc.Canny(roi_histo, roi_canny, 250, 150);
        Imgproc.HoughLines(roi_canny, roi_lines, 1, Math.PI / 180, 50);
        Mat mRgba = new Mat(roi_canny.size(), CvType.CV_8UC3, Scalar.all(0));
/////////////////////Hough transform///////////////////////////////////////////////////////////
        for (int i = 0; i < roi_lines.rows(); i++) {
            double val[] = roi_lines.get(i, 0);
//            System.out.println(roi_lines.get(i, 0));
//            Imgproc.line(ik, new Point(val[0], val[1]), new Point(val[2], val[1]), new Scalar(0, 0, 255), 2);
            double rho1 = val[0];
            double theta1 = val[1];
            double cosTheta = Math.cos(theta1);
            double sinTheta = Math.sin(theta1);
            double x0 = cosTheta * rho1;
            double y0 = sinTheta * rho1;
            Point pt1 = new Point(x0 + 10000 * (-sinTheta), y0 + 10000 * cosTheta);
            Point pt2 = new Point(x0 - 10000 * (-sinTheta), y0 - 10000 * cosTheta);
            Imgproc.line(mRgba, pt1, pt2, new Scalar(0, 0, 255), 2);
        }
        MatOfPoint2f srcTri = new MatOfPoint2f();
        Point[] canonicalPoints = new Point[4];
        canonicalPoints[0] = new Point(-30, 60);
        canonicalPoints[1] = new Point(mRgba.cols() + 50, -50);
        canonicalPoints[2] = new Point(mRgba.cols() + 100, mRgba.rows() + 50);
        canonicalPoints[3] = new Point(-50, mRgba.rows() + 50);
        srcTri.fromArray(canonicalPoints);
//////////////////////////////////////////////////////////////
        MatOfPoint2f dstTri = new MatOfPoint2f();
        Point[] canonicalPoints1 = new Point[4];
        canonicalPoints1[0] = new Point(0, 0);
        canonicalPoints1[1] = new Point(mRgba.cols() - 1, 0);
        canonicalPoints1[2] = new Point(mRgba.cols() - 1, mRgba.rows() - 1);
        canonicalPoints1[3] = new Point(0, mRgba.rows() - 1);
        dstTri.fromArray(canonicalPoints1);

        Mat m = new Mat(4, 1, CvType.CV_32FC2);
        m = Imgproc.getAffineTransform(srcTri, dstTri);
        Imgproc.warpAffine(mRgba, mRgba, m, mRgba.size());

        Imgcodecs.imwrite("123.jpg", mRgba);

so my question is am i in the right track and my numbers are right? and how to get them ? and the error .

Assertion failed in getAffineTransform

so i am just trying to align this image

here

and i am following these steps here

so after performing hough transform the result was this image

image description

and now i am performing affine Transform and i am getting the Cvtype error

OpenCV Error: Assertion failed (src.checkVector(2, CV_32F) == 3 && dst.checkVector(2, CV_32F) == 3) in getAffineTransform, file /home/tomna/Desktop/opencv-3.1.0/modules/imgproc/src/imgwarp.cpp, line 6360 Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: /home/tomna/Desktop/opencv-3.1.0/modules/imgproc/src/imgwarp.cpp:6360: error: (-215) src.checkVector(2, CV_32F) == 3 && dst.checkVector(2, CV_32F) == 3 in function getAffineTransform

]

here is my code

        System.out.println("Detecting Charachters");
        Mat roi_image = ("122.jpg");
        Mat element = getStructuringElement(MORPH_RECT, new Size(2, 2));
        Mat Kernel = Mat.ones(new Size(1, 1), MORPH_RECT);
        Mat roi_canny = new Mat();
        Mat roi_lines = new Mat();
        Mat roi_bila = new Mat();
        Mat roi_histo = new Mat();
        Mat roi_morphologyEx = new Mat();
        Mat roi_grey = new Mat();

        Mat roi_sobel = new Mat();

        Imgproc.cvtColor(roi_image, roi_image, Imgproc.COLOR_BGR2GRAY);
        Imgproc.equalizeHist(roi_image, roi_histo);

/////////////////edge detection/////////////////////////////////////////////////////////////////
        Imgproc.Canny(roi_histo, roi_canny, 250, 150);
        Imgproc.HoughLines(roi_canny, roi_lines, 1, Math.PI / 180, 50);
        Mat mRgba = new Mat(roi_canny.size(), CvType.CV_8UC3, Scalar.all(0));
/////////////////////Hough transform///////////////////////////////////////////////////////////
        for (int i = 0; i < roi_lines.rows(); i++) {
            double val[] = roi_lines.get(i, 0);
//            System.out.println(roi_lines.get(i, 0));
//            Imgproc.line(ik, new Point(val[0], val[1]), new Point(val[2], val[1]), new Scalar(0, 0, 255), 2);
            double rho1 = val[0];
            double theta1 = val[1];
            double cosTheta = Math.cos(theta1);
            double sinTheta = Math.sin(theta1);
            double x0 = cosTheta * rho1;
            double y0 = sinTheta * rho1;
            Point pt1 = new Point(x0 + 10000 * (-sinTheta), y0 + 10000 * cosTheta);
            Point pt2 = new Point(x0 - 10000 * (-sinTheta), y0 - 10000 * cosTheta);
            Imgproc.line(mRgba, pt1, pt2, new Scalar(0, 0, 255), 2);
        }
        MatOfPoint2f srcTri = new MatOfPoint2f();
        Point[] canonicalPoints = new Point[4];
        canonicalPoints[0] = new Point(-30, 60);
        canonicalPoints[1] = new Point(mRgba.cols() + 50, -50);
        canonicalPoints[2] = new Point(mRgba.cols() + 100, mRgba.rows() + 50);
        canonicalPoints[3] = new Point(-50, mRgba.rows() + 50);
        srcTri.fromArray(canonicalPoints);
//////////////////////////////////////////////////////////////
        MatOfPoint2f dstTri = new MatOfPoint2f();
        Point[] canonicalPoints1 = new Point[4];
        canonicalPoints1[0] = new Point(0, 0);
        canonicalPoints1[1] = new Point(mRgba.cols() - 1, 0);
        canonicalPoints1[2] = new Point(mRgba.cols() - 1, mRgba.rows() - 1);
        canonicalPoints1[3] = new Point(0, mRgba.rows() - 1);
        dstTri.fromArray(canonicalPoints1);

        Mat m = new Mat(4, 1, CvType.CV_32FC2);
        m = Imgproc.getAffineTransform(srcTri, dstTri);
        Imgproc.warpAffine(mRgba, mRgba, m, mRgba.size());

        Imgcodecs.imwrite("123.jpg", mRgba);

so my question is am i in the right track and my numbers are right? and how to get them ? and the error . . update after deleting the 4th parameter no i am having troubles with the numbers i keep getting the image not straight here are my numbers and the image

image description

MatOfPoint2f srcTri = new MatOfPoint2f();
        System.out.println(roi_histo.cols() +20);
        Point[] canonicalPoints = new Point[3];
        canonicalPoints[0] = new Point(-15, 15);
        canonicalPoints[1] = new Point(roi_histo.cols() +20, +20);
        canonicalPoints[2] = new Point(roi_histo.cols() + 5, roi_histo.rows() + 5);
        srcTri.fromArray(canonicalPoints);
//////////////////////////////////////////////////////////////
        MatOfPoint2f dstTri = new MatOfPoint2f();
        Point[] canonicalPoints1 = new Point[3];
        canonicalPoints1[0] = new Point(0, 0);
        canonicalPoints1[1] = new Point(roi_histo.cols() - 1, 0);
        canonicalPoints1[2] = new Point(roi_histo.cols() - 1, roi_histo.rows() - 1);
        dstTri.fromArray(canonicalPoints1);