private Mat featuresVectorBinarization(Mat fv){ int size = (int) fv.total() * fv.channels(); double[] buff = new double[size]; fv.get(0, 0, buff); for(int i = 0; i < size; i++) { buff[i] = (buff[i] >= 0) ? 1 : 0; } Mat bv = new Mat(fv.size(), CvType.CV_8U); bv.put(0, 0, buff); return bv; }
int imgSize = frame.total()*frame.elemSize(); int bytes=0; int clientSock;
Mat mat = ... byte[] bytes = new byte[mat.total()*mat.elemSize()]; mat.get(0,0,bytes); // now somehow save mat.type(), mat.rows(), mat.cols() and the bytes, later restore it: Mat m2 = new Mat(rows,cols,type); m2.put(0,0, bytes);
int size = (int)( mat.total() * mat.channels() );
public void run() { try { final int imgsize = (int) (img.total()*img.channels()); byte[] data = new byte[imgsize]; img.get(0,0,data);
Mat A = Highgui.imread(image_addr); //"image_addr" is the address of the image Mat C = A.clone(); A.convertTo(A, CvType.CV_64FC3); // New line added. int size = (int) (A.total() * A.channels()); double[] temp = new double[size]; // use double[] instead of byte[] A.get(0, 0, temp); for (int i = 0; i < size; i++) temp[i] = (temp[i] / 2); // no more casting required. C.put(0, 0, temp);
public static double calculatePsnr(Mat I1, Mat I2) { Mat s1 = new Mat(); Core.absdiff(I1, I2, s1); // |I1 - I2| s1.convertTo(s1, CvType.CV_32F); // cannot make a square on 8 bits s1 = s1.mul(s1); // |I1 - I2|^2 Scalar s = Core.sumElems(s1); // sum elements per channel double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels if (sse <= 1e-10) { // for small values return zero return 0; } else { double mse = sse / (double) (I1.channels() * I1.total()); double psnr = 10.0 * Math.log10((255 * 255) / mse); return psnr; } }
private void filter(Mat src){ Mat dst = src.clone(); dst.convertTo(dst, CvType.CV_64FC3); // New line added. int size = (int) (dst.total() * dst.channels()); double[] pixel = new double[size]; // use double[] instead of byte[] dst.get(0, 0, pixel); for(int i = 0; i < size; i+=src.channels()) { double s=pixel[i+0]+pixel[i+1]+pixel[i+2]; if(s!=0.0) { pixel[i+0]=(pixel[i+0]/s)*255; pixel[i+1]=(pixel[i+1]/s)*255; pixel[i+2]=(pixel[i+2]/s)*255; } } src.put(0, 0, pixel); }
protected void execute() { out = gray(); Imgproc.equalizeHist(out, out); Core.normalize(out, out, min, max, Core.NORM_MINMAX); Imgproc.adaptiveThreshold(out, out, 255, Imgproc.THRESH_BINARY, Imgproc.ADAPTIVE_THRESH_MEAN_C, blocksize, reduction); byte[] data = new byte[(int) out.total()]; out.get(0, 0, data); this.tessBaseAPI.setImage(data, out.width(), out.height(), out.channels(), (int) out.step1()); String utf8Text = this.tessBaseAPI.getUTF8Text(); int score = this.tessBaseAPI.meanConfidence(); this.tessBaseAPI.clear(); if (score >= SIMPLETEXT_MIN_SCORE && utf8Text.length() > 0) { simpleText = utf8Text; } else { simpleText = new String(); } }