当前位置: 首页>>代码示例>>Java>>正文


Java Imgproc.resize方法代码示例

本文整理汇总了Java中org.opencv.imgproc.Imgproc.resize方法的典型用法代码示例。如果您正苦于以下问题:Java Imgproc.resize方法的具体用法?Java Imgproc.resize怎么用?Java Imgproc.resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opencv.imgproc.Imgproc的用法示例。


在下文中一共展示了Imgproc.resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildGaussianPyramid

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat[] buildGaussianPyramid(Mat img, int level) {
	Mat[] gaussPyr = new Mat[level];
	Mat mask = filterMask(img);
	Mat tmp = new Mat();
	Imgproc.filter2D(img, tmp, -1, mask);
	gaussPyr[0] = tmp.clone();
	Mat tmpImg = img.clone();
	for (int i = 1; i < level; i++) {
		// resize image
		Imgproc.resize(tmpImg, tmpImg, new Size(), 0.5, 0.5, Imgproc.INTER_LINEAR);
		// blur image
		tmp = new Mat();
		Imgproc.filter2D(tmpImg, tmp, -1, mask);
		gaussPyr[i] = tmp.clone();
	}
	return gaussPyr;
}
 
开发者ID:IsaacChanghau,项目名称:OptimizedImageEnhance,代码行数:18,代码来源:ImgDecompose.java

示例2: showResult

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void showResult(Mat img) {
    Imgproc.resize(img, img, new Size(640, 480));
    MatOfByte matOfByte = new MatOfByte();
    Imgcodecs.imencode(".jpg", img, matOfByte);
    byte[] byteArray = matOfByte.toArray();
    BufferedImage bufImage = null;
    try {
        InputStream in = new ByteArrayInputStream(byteArray);
        bufImage = ImageIO.read(in);
        JFrame frame = new JFrame();
        frame.getContentPane().add(new JLabel(new ImageIcon(bufImage)));
        frame.pack();
        frame.setVisible(true);
    } catch (IOException | HeadlessException e) {
        e.printStackTrace();
    }
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:18,代码来源:OpenCVFlow.java

示例3: resize

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * 
* @Title: resize 
* @Description: 缩放图片
* @param srcImg
* @param scale
* @param scaledWidth
* @return
* Mat 
* @throws
 */
public static Mat resize(Mat srcImg, float scale, int scaledWidth) {
	Mat inputImg = new Mat();
	// 计算收缩比例
	//float scale = srcImg.cols() / (float) scaledWidth;
	if (srcImg.cols() > scaledWidth) {
		// 缩小图像,同时保持相同的纵横比
		// Math.round == cvRound(javacv没有cvRound)
		int scaledHeight = Math.round(srcImg.rows() / scale);
		Imgproc.resize(srcImg, inputImg, new Size(scaledWidth, scaledHeight));
	} else {
		// 当图片足够小的时候,直接使用
		srcImg.copyTo(inputImg);
	}
	return inputImg;
}
 
开发者ID:IaHehe,项目名称:classchecks,代码行数:27,代码来源:ImgprocessUtils.java

示例4: showImage

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void showImage(Mat img) {
	if (SizeCustom) {
		Imgproc.resize(img, img, new Size(Height, Width));
	}
	// Highgui.imencode(".jpg", img, matOfByte);
	// byte[] byteArray = matOfByte.toArray();
	BufferedImage bufImage = null;
	try {
		// InputStream in = new ByteArrayInputStream(byteArray);
		// bufImage = ImageIO.read(in);
		bufImage = toBufferedImage(img);
		image.setImage(bufImage);
		Window.pack();
		label.updateUI();
		Window.setVisible(true);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:IsaacChanghau,项目名称:ImageEnhanceViaFusion,代码行数:20,代码来源:ImShow.java

示例5: buildLaplacianPyramid

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat[] buildLaplacianPyramid(Mat img, int level) {
	Mat[] lapPyr = new Mat[level];
	lapPyr[0] = img.clone();
	Mat tmpImg = img.clone();
	for (int i = 1; i < level; i++) {
		// resize image
		Imgproc.resize(tmpImg, tmpImg, new Size(), 0.5, 0.5, Imgproc.INTER_LINEAR);
		lapPyr[i] = tmpImg.clone();
	}
	// calculate the DoG
	for (int i = 0; i < level - 1; i++) {
		Mat tmpPyr = new Mat();
		Imgproc.resize(lapPyr[i + 1], tmpPyr, lapPyr[i].size(), 0, 0, Imgproc.INTER_LINEAR);
		Core.subtract(lapPyr[i], tmpPyr, lapPyr[i]);
	}
	return lapPyr;
}
 
开发者ID:IsaacChanghau,项目名称:OptimizedImageEnhance,代码行数:18,代码来源:ImgDecompose.java

示例6: FindMatch

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
int FindMatch(Mat test_image) {
        Imgproc.dilate(test_image, test_image,
                Imgproc.getStructuringElement(Imgproc.CV_SHAPE_CROSS,
                        new Size(3,3)));
        // Resize the image
        Imgproc.resize(test_image, test_image, new Size(width, height));
        // Convert the image to grayscale
//        Imgproc.cvtColor(test_image, test_image, Imgproc.COLOR_RGB2GRAY);
        // Adaptive Threshold
        Imgproc.adaptiveThreshold(test_image, test_image, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C,
                Imgproc.THRESH_BINARY_INV, 15,2);

        Mat test = new Mat(1, test_image.rows() *
                        test_image.cols(), CvType.CV_32FC1);
        int count = 0;
        for (int i = 0 ; i < test_image.rows(); i++) {
            for (int j = 0; j < test_image.cols(); j++) {
                test.put(0, count, test_image.get(i, j)[0]);
                count++;
            }
        }

        Mat results = new Mat(1, 1, CvType.CV_8U);

        knn.find_nearest(test, 10, results, new Mat(), new Mat());
        Log.i("Result:", "" + results.get(0,0)[0]);

        return (int)(results.get(0,0)[0]);
    }
 
开发者ID:jocstech,项目名称:AndroidCameraSudokuSolver,代码行数:30,代码来源:DigitRecognizer.java

示例7: LaplacianPyramid

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat[] LaplacianPyramid(Mat img, int level) {
	Mat[] lapPyr = new Mat[level];
	//Mat mask = filterMask(img);
	lapPyr[0] = img.clone();
	Mat tmpImg = img.clone();
	for (int i = 1; i < level; i++) {
		// resize image
		Imgproc.resize(tmpImg, tmpImg, new Size(), 0.5, 0.5, Imgproc.INTER_LINEAR);
		lapPyr[i] = tmpImg.clone();
	}
	// calculate the DoG
	for (int i = 0; i < level - 1; i++) {
		Mat tmpPyr = new Mat();
		Imgproc.resize(lapPyr[i + 1], tmpPyr, lapPyr[i].size(), 0, 0, Imgproc.INTER_LINEAR);
		Core.subtract(lapPyr[i], tmpPyr, lapPyr[i]);
	}
	return lapPyr;
}
 
开发者ID:IsaacChanghau,项目名称:ImageEnhanceViaFusion,代码行数:19,代码来源:Pyramid.java

示例8: preprocess

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
static Bitmap preprocess(Mat frame, int width, int height) {
    // convert to grayscale
    Mat frameGrey = new Mat(height, width, CvType.CV_8UC1);
    Imgproc.cvtColor(frame, frameGrey, Imgproc.COLOR_BGR2GRAY, 1);

    // rotate
    Mat rotatedFrame = new Mat(width, height, frameGrey.type());
    Core.transpose(frameGrey, rotatedFrame);
    Core.flip(rotatedFrame, rotatedFrame, Core.ROTATE_180);

    // resize to match the surface view
    Mat resizedFrame = new Mat(width, height, rotatedFrame.type());
    Imgproc.resize(rotatedFrame, resizedFrame, new Size(width, height));

    // crop
    Mat ellipseMask = getEllipseMask(width, height);
    Mat frameCropped = new Mat(resizedFrame.rows(), resizedFrame.cols(), resizedFrame.type(), new Scalar(0));
    resizedFrame.copyTo(frameCropped, ellipseMask);

    // histogram equalisation
    Mat frameHistEq = new Mat(frame.rows(), frameCropped.cols(), frameCropped.type());
    Imgproc.equalizeHist(frameCropped, frameHistEq);

    // convert back to rgba
    Mat frameRgba = new Mat(frameHistEq.rows(), frameHistEq.cols(), CvType.CV_8UC4);
    Imgproc.cvtColor(frameHistEq, frameRgba, Imgproc.COLOR_GRAY2RGBA);

    // crop again to correct alpha
    Mat frameAlpha = new Mat(frameRgba.rows(), frameRgba.cols(), CvType.CV_8UC4, new Scalar(0, 0, 0, 0));
    frameRgba.copyTo(frameAlpha, ellipseMask);

    // convert to bitmap
    Bitmap bmp = Bitmap.createBitmap(frameAlpha.cols(), frameAlpha.rows(), Bitmap.Config.ARGB_4444);
    Utils.matToBitmap(frameAlpha, bmp);

    return bmp;
}
 
开发者ID:jorenham,项目名称:fingerblox,代码行数:38,代码来源:ImageProcessing.java

示例9: getOpenCvLines

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static List<Line> getOpenCvLines(Mat original, int scale, double minLength) {
    Mat raw = new Mat();
    Imgproc.resize(original.clone(), raw, new Size((int) (original.size().width/scale), (int) (original.size().height/scale)));
    if(raw.channels() > 1) {
        Imgproc.cvtColor(raw, raw, Imgproc.COLOR_RGB2GRAY);
    }
    Imgproc.equalizeHist(raw, raw);
    Imgproc.blur(raw, raw, new Size(3,3));
    //Line Segment Detection 2
    Mat linesM1 = new Mat();
    //LineSegmentDetector detector = Imgproc.createLineSegmentDetector(Imgproc.LSD_REFINE_ADV, 0.6, 0.3, 2.6, 22.5, 0, 0.3,256);
    //LineSegmentDetector detector = Imgproc.createLineSegmentDetector(Imgproc.LSD_REFINE_STD, 0.5, 0.4,2.0, 19.5, 0, 0.6, 32);
    //Reference for final glyph detection

    detector.detect(raw, linesM1);
    ArrayList<Line> lines = new ArrayList<Line>();
    for (int x = 0; x < linesM1.rows(); x++)  {
        double[] vec = linesM1.get(x, 0);
        Point start = new Point(vec[0],vec[1]);
        Point end = new Point(vec[2], vec[3]);
        Line line = new Line(start, end);
        line = new Line(new Point((int)line.x1*scale, (int) line.y1*scale), new Point((int)line.x2*scale, (int)line.y2*scale));
        if(line.length() > minLength) lines.add(line);
    }

    raw.release();
    linesM1.release();

    return lines;
}
 
开发者ID:GTHSRobotics,项目名称:DogeCV,代码行数:31,代码来源:Lines.java

示例10: preprocess

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public Mat preprocess(Mat input_mat, Size size) {
    Mat resized = new Mat();
    Mat grey = new Mat();
    Imgproc.resize(input_mat,resized,size);
    Imgproc.cvtColor(resized,grey,Imgproc.COLOR_BGRA2GRAY);
    //grey = resized
    return grey;
}
 
开发者ID:SCHS-Robotics,项目名称:Team9261-2017-2018,代码行数:9,代码来源:GlyphDetector.java

示例11: rotateCropAndResizePreview

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Resize, crop and rotate the camera preview frame
 *
 * @param bytes  preview data
 * @param width  original width
 * @param height original height
 * @param params image processing parameters
 * @return
 */
public static Bitmap rotateCropAndResizePreview(byte[] bytes, int width, int height, PreviewResizeParams params)
{
    Size finalSize = new Size(params.newWidth, params.newHeight);
    Rect cropRect = new Rect(params.cropX, params.cropY, params.cropWidth, params.cropHeight);

    Mat rawMat = new Mat(height * 3 / 2, width, CvType.CV_8UC1); // YUV data
    rawMat.put(0, 0, bytes);
    Mat rgbMat = new Mat(height, width, CvType.CV_8UC4); // RGBA image
    Imgproc.cvtColor(rawMat, rgbMat, Imgproc.COLOR_YUV2RGBA_NV21);

    //rotate clockwise
    Mat rotatedMat = rotateFrame(rgbMat, params.rotation);

    //crop rect from image
    Mat croppedMat = new Mat(rotatedMat, cropRect);

    //resize
    if (finalSize.area() > 0)
        Imgproc.resize(croppedMat, croppedMat, finalSize);


    Bitmap bmp = Bitmap.createBitmap(croppedMat.cols(), croppedMat.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(croppedMat, bmp);

    return bmp;
}
 
开发者ID:ravindu1024,项目名称:android-imaging-utils,代码行数:36,代码来源:ImagingUtils.java

示例12: resize

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private static void resize(Mat img, Size size) {
    int interpolation;
    if (MathUtil.equal(size.area(), img.size().area()))
        return;
    else if (size.width > img.size().width && size.height > img.size().height)
        interpolation = Imgproc.CV_INTER_CUBIC; //enlarge image
    else if (size.width < img.size().width && size.height < img.size().height)
        interpolation = Imgproc.CV_INTER_AREA; //shrink image
    else
        interpolation = Imgproc.CV_INTER_LINEAR; //not entirely sure, so use safe option
    Imgproc.resize(img, img, size, 0, 0, interpolation);
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:13,代码来源:Transform.java

示例13: recognitionByLBPH

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static void recognitionByLBPH() {
	String modelFilePath = "E:\\classchecks\\2017417\\train\\trainLBPHModel-201704171530.xml";
	LBPHFaceRecognizer model = TrainFaces.loadLBPHModel(modelFilePath);
	Mat waitRecoMat = Imgcodecs.imread("E:\\classchecks\\2017417\\split\\14.jpg");
	//Imgcodecs.imr
	Mat preProc = PreProcessFace.rawProcessedFace(waitRecoMat);
	ImageGui.imshow(preProc, "preProc");
	Imgproc.resize(preProc, preProc, new Size(92, 112));
	//Mat reconstructMat = Recognition.reconstructFace(model, preProc);
	
	//double similarity = Recognition.getSimilarity(preProc, reconstructMat);
       //System.out.println("similarity=" + similarity);
       int pridictLabel = model.predict_label(preProc);
       System.out.println("pridictLabel=" + pridictLabel);
}
 
开发者ID:IaHehe,项目名称:classchecks,代码行数:16,代码来源:Test.java

示例14: getPyramidDownAtLevel

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private static Mat getPyramidDownAtLevel(Mat m, int level) {
    if (level == 0) {
        return m;
    }
    int cols = m.cols();
    int rows = m.rows();
    for (int i = 0; i < level; i++) {
        cols = (cols + 1) / 2;
        rows = (rows + 1) / 2;
    }
    Mat r = new Mat(rows, cols, m.type());
    Imgproc.resize(m, r, new Size(cols, rows));
    return r;
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:15,代码来源:TemplateMatching.java

示例15: resize

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static double resize(Mat im, int height) {
    /*
       @return: a double indicating the shrink ratio
         = new height / old height
     */

    Size size = im.size();
    int width = (int) (height * size.width / size.height);

    Imgproc.resize(im, im, new Size(width, height));
    return (double) height / size.height;
}
 
开发者ID:hgs1217,项目名称:Paper-Melody,代码行数:13,代码来源:Util.java


注:本文中的org.opencv.imgproc.Imgproc.resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。