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=inchesDim.x;
float 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.
my downvote. read docs before asking anywhere, please