Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to Convert Mat to ArrayList<point> Java

Hi, I could not able to convert Mat to List<ponit>.Could you please help me on this.

My source code looks like:

Mat gray = new Mat(in.size(),CvType.CV_8UC1); if(in.channels()==3){ Imgproc.cvtColor(in, gray, Imgproc.COLOR_RGB2GRAY); }else if(in.channels()==1){ in.copyTo(gray); }else{ throw new IOException("Invalid image type:"+in.type()); }

 // we first blur the gray scale image 
    Mat blurred = new Mat(gray.size(),gray.type()); 
    Mat binary4c = new Mat(gray.size(),gray.type()); 
    Imgproc.GaussianBlur(gray,blurred,new Size(0,0),1,1); 
    // next we threshold the blurred image 
    Imgproc.threshold(blurred,binary4c,128,255,Imgproc.THRESH_BINARY);

    Mat mHierarchy = new Mat(); 
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 
    Imgproc.findContours(binary4c, contours, mHierarchy, Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
    int dpi=300; 
    List<Point> corners= (I failed here)  // find corners from contour
    Point inchesDim=(I failed here) // select business card dimensions and compute pixels

Could anyone please help on this.Please Save my day

How to Convert Mat to ArrayList<point> Java

Hi, I could not able to convert Mat to List<ponit>.Could you please help me on this.

My source code looks like:

 Mat gray = new Mat(in.size(),CvType.CV_8UC1);
        if(in.channels()==3){
            Imgproc.cvtColor(in, gray, Imgproc.COLOR_RGB2GRAY);
        }else if(in.channels()==1){
            in.copyTo(gray);
        }else{
            throw new IOException("Invalid image type:"+in.type());
        }

}

     // we first blur the gray scale image 
     Mat blurred = new Mat(gray.size(),gray.type()); 
     Mat binary4c = new Mat(gray.size(),gray.type()); 
     Imgproc.GaussianBlur(gray,blurred,new Size(0,0),1,1); 
     // next we threshold the blurred image 
     Imgproc.threshold(blurred,binary4c,128,255,Imgproc.THRESH_BINARY);

     Mat mHierarchy = new Mat(); 
     List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 
     Imgproc.findContours(binary4c, contours, mHierarchy, Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
     int dpi=300; 
     List<Point> corners= (I failed here)  // find corners from contour
     Point inchesDim=(I failed here) // select business card dimensions and compute pixels

Could anyone please help on this.Please Save my day

How to Convert Mat to ArrayList<point> Java

Hi, I could not able to convert Mat to List<ponit>.Could you please help me on this.

My source code looks like:

 Mat gray = new Mat(in.size(),CvType.CV_8UC1);
        if(in.channels()==3){
            Imgproc.cvtColor(in, gray, Imgproc.COLOR_RGB2GRAY);
        }else if(in.channels()==1){
            in.copyTo(gray);
        }else{
            throw new IOException("Invalid image type:"+in.type());
        }

     // we first blur the gray scale image 
        Mat blurred = new Mat(gray.size(),gray.type()); 
        Mat binary4c = new Mat(gray.size(),gray.type()); 
        Imgproc.GaussianBlur(gray,blurred,new Size(0,0),1,1); 
        // next we threshold the blurred image 
        Imgproc.threshold(blurred,binary4c,128,255,Imgproc.THRESH_BINARY);

        Mat mHierarchy = new Mat(); 
        List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 
        Imgproc.findContours(binary4c, contours, mHierarchy, Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
        int dpi=300; 
        List<Point> corners= (I failed here) ???  // find corners from contour
        Point inchesDim=(I failed here) inchesDim=??? // select business card dimensions and compute pixels

Could anyone please help on this.Please Save my daythis.

How to Convert Mat to ArrayList<point> Java

Hi, I could not able to convert Mat to List<ponit>.Could you please help me on this.

My source code looks like:

 Mat gray = new Mat(in.size(),CvType.CV_8UC1);
        if(in.channels()==3){
            Imgproc.cvtColor(in, gray, Imgproc.COLOR_RGB2GRAY);
        }else if(in.channels()==1){
            in.copyTo(gray);
        }else{
            throw new IOException("Invalid image type:"+in.type());
        }

     // we first blur the gray scale image 
        Mat blurred = new Mat(gray.size(),gray.type()); 
        Mat binary4c = new Mat(gray.size(),gray.type()); 
        Imgproc.GaussianBlur(gray,blurred,new Size(0,0),1,1); 
        // next we threshold the blurred image 
        Imgproc.threshold(blurred,binary4c,128,255,Imgproc.THRESH_BINARY);

        Mat mHierarchy = new Mat(); 
        List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 
        Imgproc.findContours(binary4c, contours, mHierarchy, Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
        int dpi=300; 
        List<Point> corners= ???  // find corners from contour
getOuterQuad(contours);
        Point inchesDim=??? inchesDim=?????? // select business card dimensions and compute pixels

Could anyone please help on this.

How to Convert Mat to ArrayList<point> Java

Hi, I could not able to convert Mat to List<ponit>.Could you please help me on this.

My source code looks like:

 Mat gray = new Mat(in.size(),CvType.CV_8UC1);
        if(in.channels()==3){
            Imgproc.cvtColor(in, gray, Imgproc.COLOR_RGB2GRAY);
        }else if(in.channels()==1){
            in.copyTo(gray);
        }else{
            throw new IOException("Invalid image type:"+in.type());
        }

     // we first blur the gray scale image 
        Mat blurred = new Mat(gray.size(),gray.type()); 
        Mat binary4c = new Mat(gray.size(),gray.type()); 
        Imgproc.GaussianBlur(gray,blurred,new Size(0,0),1,1); 
        // next we threshold the blurred image 
        Imgproc.threshold(blurred,binary4c,128,255,Imgproc.THRESH_BINARY);

        Mat mHierarchy = new Mat(); 
        List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 
        Imgproc.findContours(binary4c, contours, mHierarchy, Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
        int dpi=300; 
        List<Point> corners= getOuterQuad(contours);
           // select dpi, 300 is optimal for OCR

List<point> corners=????; // find corners from contour Point inchesDim=?????? inchesDim=?????; // select business card dimensions and compute pixels float inchesWide=inchesDim.x; float inchesHigh=inchesDim.y; pixelsWide=(int)(inchesWidedpi); // width and height of business card at given dpi pixelsHigh=(int)(inchesHighdpi); // now establish from and to parameters for warpPerspective Point[] fromPts = {corners.get(0),corners.get(1),corners.get(2),corners.get(3)}; Point[] toPts = {new Point(0,0), new Point(0,pixelsHigh), new Point(pixelsWide,pixelsHigh), new Point(pixelsWide,0)}; MatOfPoint2f srcPts = new MatOfPoint2f(); srcPts.fromArray(fromPts); MatOfPoint2f dstPts = new MatOfPoint2f(); dstPts.fromArray(toPts); Mat hh=Calib3d.findHomography(srcPts,dstPts); Mat rectified=Mat.zeros(pixelsHigh,pixelsWide,gray.type()); Imgproc.warpPerspective(gray,rectified, hh,rectified.size()); // condition the output image a little Core.normalize(rectified,rectified,0,255,Core.NORM_MINMAX,CvType.CV_8UC1); float meanA=Core.mean(rectified).val[0]; if(meanA>128) Core.bitwise_not(rectified,rectified);

Could anyone please help on this.

How to Convert Mat to ArrayList<point> Java

Hi, I could not able to convert Mat to List<ponit>.Could you please help me on this.

My source code looks like:

 Mat gray = new Mat(in.size(),CvType.CV_8UC1);
        if(in.channels()==3){
            Imgproc.cvtColor(in, gray, Imgproc.COLOR_RGB2GRAY);
        }else if(in.channels()==1){
            in.copyTo(gray);
        }else{
            throw new IOException("Invalid image type:"+in.type());
        }

     // we first blur the gray scale image 
        Mat blurred = new Mat(gray.size(),gray.type()); 
        Mat binary4c = new Mat(gray.size(),gray.type()); 
        Imgproc.GaussianBlur(gray,blurred,new Size(0,0),1,1); 
        // next we threshold the blurred image 
        Imgproc.threshold(blurred,binary4c,128,255,Imgproc.THRESH_BINARY);

        Mat mHierarchy = new Mat(); 
        List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 
        Imgproc.findContours(binary4c, contours, mHierarchy, Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
       int dpi=300;    // select dpi, 300 is optimal for OCR

List<point> corners=????; List<Point> corners=getOuterQuad(contours); // find corners from contour Point inchesDim=?????; /*List<Point> corners= new ArrayList<>(); for(int i=0;i<=contours.size();i++){ Converters.Mat_to_vector_Point(contours.get(i), corners); }*/ //Point inchesDim=getFormatDim(); // select business card dimensions and compute pixels float inchesWide=inchesDim.x; inchesWide=(float) 3.5; float inchesHigh=inchesDim.y; pixelsWide=(int)(inchesWidedpi); inchesHigh=(float) 2.0; int pixelsWide = (int)(inchesWide*dpi); // width and height of business card at given dpi pixelsHigh=(int)(inchesHighdpi); int pixelsHigh = (int)(inchesHigh*dpi); // now establish from and to parameters for warpPerspective Point[] fromPts = {corners.get(0),corners.get(1),corners.get(2),corners.get(3)}; Point[] toPts = {new Point(0,0), new Point(0,pixelsHigh), new Point(pixelsWide,pixelsHigh), new Point(pixelsWide,0)}; MatOfPoint2f srcPts = new MatOfPoint2f(); srcPts.fromArray(fromPts); MatOfPoint2f dstPts = new MatOfPoint2f(); dstPts.fromArray(toPts); Mat hh=Calib3d.findHomography(srcPts,dstPts); Mat rectified=Mat.zeros(pixelsHigh,pixelsWide,gray.type()); Imgproc.warpPerspective(gray,rectified, hh,rectified.size()); // condition the output image a little Core.normalize(rectified,rectified,0,255,Core.NORM_MINMAX,CvType.CV_8UC1); float meanA=Core.mean(rectified).val[0]; meanA=(float) Core.mean(rectified).val[0]; if(meanA>128) Core.bitwise_not(rectified,rectified);

{ Core.bitwise_not(rectified,rectified); }

Could anyone please help on this.

How to Convert Mat to ArrayList<point> Java

Hi, I could not able to convert Mat to List<ponit>.Could List<ponit> and getting pixels.Could you please help me on this.

My source code looks like:

     // we first blur the gray scale image 
        Mat blurred = new Mat(gray.size(),gray.type()); 
        Mat binary4c = new Mat(gray.size(),gray.type()); 
        Imgproc.GaussianBlur(gray,blurred,new Size(0,0),1,1); 
        // next we threshold the blurred image 
        Imgproc.threshold(blurred,binary4c,128,255,Imgproc.THRESH_BINARY);

        Mat mHierarchy = new Mat(); 
        List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 
        Imgproc.findContours(binary4c, contours, mHierarchy, Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
       int dpi=300;    // select dpi, 300 is optimal for OCR
    List<Point> corners=getOuterQuad(contours); // find corners from contour
    /*List<Point> corners= new ArrayList<>();
    for(int i=0;i<=contours.size();i++){
        Converters.Mat_to_vector_Point(contours.get(i), corners);
    }*/

    //Point inchesDim=getFormatDim(); Point inchesDim=????????????????????????;  // select business card dimensions and compute pixels
    float inchesWide=(float) 3.5;
    float inchesHigh=(float) 2.0;
    int pixelsWide = (int)(inchesWide*dpi); // width and height of business card at given dpi
    int pixelsHigh = (int)(inchesHigh*dpi);
    // now establish from and to parameters for warpPerspective
    Point[] fromPts = {corners.get(0),corners.get(1),corners.get(2),corners.get(3)};
    Point[] toPts = {new Point(0,0), new Point(0,pixelsHigh), new Point(pixelsWide,pixelsHigh), new Point(pixelsWide,0)};
    MatOfPoint2f srcPts = new MatOfPoint2f(); srcPts.fromArray(fromPts);
    MatOfPoint2f dstPts = new MatOfPoint2f(); dstPts.fromArray(toPts);
    Mat hh=Calib3d.findHomography(srcPts,dstPts);
    Mat rectified=Mat.zeros(pixelsHigh,pixelsWide,gray.type());
    Imgproc.warpPerspective(gray,rectified, hh,rectified.size());
    // condition the output image a little
    Core.normalize(rectified,rectified,0,255,Core.NORM_MINMAX,CvType.CV_8UC1);
    float meanA=(float) Core.mean(rectified).val[0];
    if(meanA>128) {
        Core.bitwise_not(rectified,rectified);
    }

Could anyone please help on this.

How to Convert Mat to ArrayList<point> Java

Hi, I could not able to convert Mat to List<ponit> and getting pixels.Could you please help me on this.

My source code looks like:

     // we first blur the gray scale image 
        Mat blurred = new Mat(gray.size(),gray.type()); 
        Mat binary4c = new Mat(gray.size(),gray.type()); 
        Imgproc.GaussianBlur(gray,blurred,new Size(0,0),1,1); 
        // next we threshold the blurred image 
        Imgproc.threshold(blurred,binary4c,128,255,Imgproc.THRESH_BINARY);

        Mat mHierarchy = new Mat(); 
        List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 
        Imgproc.findContours(binary4c, contours, mHierarchy, Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
       int dpi=300;    // select dpi, 300 is optimal for OCR
    List<Point> corners=getOuterQuad(contours); // find corners from contour
    /*List<Point> corners= new ArrayList<>();
    for(int i=0;i<=contours.size();i++){
        Converters.Mat_to_vector_Point(contours.get(i), corners);
    }*/

    List<Point> corners=getOuterQuad(contours); //// find corners from contour
    Point inchesDim=????????????????????????;  // select business card dimensions and compute pixels
    float inchesWide=(float) 3.5;
inchesWide=inchesDim.x;
    float inchesHigh=(float) 2.0;
inchesHigh=inchesDim.y;
    int pixelsWide = (int)(inchesWide*dpi); // width and height of business card at given dpi
    int pixelsHigh = (int)(inchesHigh*dpi);
    // now establish from and to parameters for warpPerspective
    Point[] fromPts = {corners.get(0),corners.get(1),corners.get(2),corners.get(3)};
    Point[] toPts = {new Point(0,0), new Point(0,pixelsHigh), new Point(pixelsWide,pixelsHigh), new  Point(pixelsWide,0)};
    MatOfPoint2f srcPts = new MatOfPoint2f(); srcPts.fromArray(fromPts);
    MatOfPoint2f dstPts = new MatOfPoint2f(); dstPts.fromArray(toPts);
    Mat hh=Calib3d.findHomography(srcPts,dstPts);
    Mat rectified=Mat.zeros(pixelsHigh,pixelsWide,gray.type());
    Imgproc.warpPerspective(gray,rectified, hh,rectified.size());
    // condition the output image a little
    Core.normalize(rectified,rectified,0,255,Core.NORM_MINMAX,CvType.CV_8UC1);
    float meanA=(float) Core.mean(rectified).val[0];
    if(meanA>128) {
        Core.bitwise_not(rectified,rectified);
    }

Could anyone please help on this.