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


Java Mat.copyTo方法代码示例

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


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

示例1: RectangleSubROI

import org.opencv.core.Mat; //导入方法依赖的package包/类
public static Mat RectangleSubROI(Mat input, Rect rect) {
	final Mat maskCopyTo = Mat.zeros(input.size(), CvType.CV_8UC1); // ����copyTo������mask����С��ԭͼ����һ��
	// floodFill��mask��width��height�����������ͼ��������������أ��������ᱨ��
	final Mat maskFloodFill = Mat.zeros(new Size(input.cols() + 2, input.rows() + 2), CvType.CV_8UC1); // ����floodFill������mask���ߴ��ԭͼ��һЩ
	// Imgproc.circle(maskCopyTo, new Point(cc.x, cc.y), radius, Scalar.all(255), 2,
	// 8, 0); // ����Բ������
	Imgproc.rectangle(maskCopyTo, rect.tl(), rect.br(), Scalar.all(255), 2, 8, 0);
	Imgproc.floodFill(maskCopyTo, maskFloodFill,
			new Point((rect.tl().x + rect.br().x) / 2, (rect.tl().y + rect.br().y) / 2), Scalar.all(255), null,
			Scalar.all(20), Scalar.all(20), 4); // ��ˮ��䷨���Բ���ڲ�
	// MatView.imshow(maskFloodFill, "Mask of floodFill"); // ����floodFill������mask
	// MatView.imshow(maskCopyTo, "Mask of copyTo"); // ����copyTo������mask
	final Mat imgRectROI = new Mat();
	input.copyTo(imgRectROI, maskCopyTo); // ��ȡԲ�ε�ROI
	// MatView.imshow(imgCircularROI, "Circular ROI"); // ��ʾԲ�ε�ROI
	return imgRectROI;
}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:18,代码来源:ROI_Irregular.java

示例2: resize

import org.opencv.core.Mat; //导入方法依赖的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

示例3: rgbToGray

import org.opencv.core.Mat; //导入方法依赖的package包/类
/**
 * Converts a mat to gray.
 * @param mat a mat to convert
 * @param gray a mat to fill with gray data
 * @return the gray mat 
 * @see Imgproc#cvtColor(Mat, Mat, int)
 */
public static Mat rgbToGray(Mat mat, Mat gray){
	if(mat.type() == CvType.CV_8UC1)
		mat.copyTo(gray);
	else if(mat.type() == CvType.CV_8UC3)
		Imgproc.cvtColor(mat, gray, Imgproc.COLOR_RGB2GRAY);
	return gray;
}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:15,代码来源:CvProcessing.java

示例4: ridgeFrequency

import org.opencv.core.Mat; //导入方法依赖的package包/类
/**
 * Calculate ridge frequency.
 */
private double ridgeFrequency(Mat ridgeSegment, Mat segmentMask, Mat ridgeOrientation, Mat frequencies, int blockSize, int windowSize, int minWaveLength, int maxWaveLength) {

    int rows = ridgeSegment.rows();
    int cols = ridgeSegment.cols();

    Mat blockSegment;
    Mat blockOrientation;
    Mat frequency;

    for (int y = 0; y < rows - blockSize; y += blockSize) {
        for (int x = 0; x < cols - blockSize; x += blockSize) {
            blockSegment = ridgeSegment.submat(y, y + blockSize, x, x + blockSize);
            blockOrientation = ridgeOrientation.submat(y, y + blockSize, x, x + blockSize);
            frequency = calculateFrequency(blockSegment, blockOrientation, windowSize, minWaveLength, maxWaveLength);
            frequency.copyTo(frequencies.rowRange(y, y + blockSize).colRange(x, x + blockSize));
        }
    }

    // mask out frequencies calculated for non ridge regions
    Core.multiply(frequencies, segmentMask, frequencies, 1.0, CvType.CV_32FC1);

    // find median frequency over all the valid regions of the image.
    double medianFrequency = medianFrequency(frequencies);

    // the median frequency value used across the whole fingerprint gives a more satisfactory result
    Core.multiply(segmentMask, Scalar.all(medianFrequency), frequencies, 1.0, CvType.CV_32FC1);

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

示例5: preprocess

import org.opencv.core.Mat; //导入方法依赖的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

示例6: Circle

import org.opencv.core.Mat; //导入方法依赖的package包/类
public static Mat Circle(Mat circularInput, Point cc, int radius) {
	final Mat maskCopyTo = Mat.zeros(circularInput.size(), CvType.CV_8UC1); // ����copyTo������mask����С��ԭͼ����һ��
	// floodFill��mask��width��height�����������ͼ��������������أ��������ᱨ��
	final Mat maskFloodFill = Mat.zeros(new Size(circularInput.cols() + 2, circularInput.rows() + 2),
			CvType.CV_8UC1); // ����floodFill������mask���ߴ��ԭͼ��һЩ
	Imgproc.circle(maskCopyTo, new Point(cc.x, cc.y), radius, Scalar.all(255), 2, 8, 0); // ����Բ������
	Imgproc.floodFill(maskCopyTo, maskFloodFill, new Point(207, 290), Scalar.all(255), null, Scalar.all(20),
			Scalar.all(20), 4); // ��ˮ��䷨���Բ���ڲ�
	// MatView.imshow(maskFloodFill, "Mask of floodFill"); // ����floodFill������mask
	// MatView.imshow(maskCopyTo, "Mask of copyTo"); // ����copyTo������mask
	final Mat imgCircularROI = new Mat();
	circularInput.copyTo(imgCircularROI, maskCopyTo); // ��ȡԲ�ε�ROI
	// MatView.imshow(imgCircularROI, "Circular ROI"); // ��ʾԲ�ε�ROI
	return imgCircularROI;
}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:16,代码来源:ROI_Irregular.java

示例7: irregularQuadrangle_Simplified

import org.opencv.core.Mat; //导入方法依赖的package包/类
public static Mat irregularQuadrangle_Simplified(Mat irrInput, Point p1, Point p2, Point p3, Point p4,
		double shift_x, double shift_y, boolean noULandLRcorner, double ulCornerRatio, double lrCornerRatio) {
	final Mat maskCopyTo = Mat.zeros(irrInput.size(), CvType.CV_8UC1); // ����copyTo������mask����С��ԭͼ����һ��

	// �����ĵ���Ϊ��ʼ����
	final double centerX = (p1.x + p2.x + p3.x + p4.x) / 4;
	final double centerY = (p1.y + p2.y + p3.y + p4.y) / 4;
	final Point cc = new Point(centerX, centerY);

	final List<MatOfPoint> counter = new ArrayList<>();
	final Point aP1 = new Point(p1.x + shift_x, p1.y + shift_y);
	final Point aP2 = new Point(p2.x - shift_x, p2.y + shift_y);
	final Point aP3 = new Point(p3.x + shift_x, p3.y - shift_y);
	final Point aP4 = new Point(p4.x - shift_x, p4.y - shift_y);

	if (noULandLRcorner) {
		final Point aP1L = new Point(aP1.x, aP1.y + (aP3.y - aP1.y) * ulCornerRatio);
		final Point aP1R = new Point(aP1.x + (aP2.x - aP1.x) * ulCornerRatio, aP1.y);
		final Point aP4L = new Point(aP4.x - (aP4.x - aP3.x) * lrCornerRatio, aP4.y);
		final Point aP4R = new Point(aP4.x, aP4.y - (aP4.y - aP2.y) * lrCornerRatio);

		counter.add(new MatOfPoint(aP1L, aP1R, aP2, aP4R, aP4L, aP3)); // ����һ��������Ķ���Σ�û�����ϽǺ����½�
	} else
		counter.add(new MatOfPoint(aP1, aP2, aP4, aP3)); // ����һ��������Ķ����

	// floodFill��mask��width��height�����������ͼ��������������أ��������ᱨ��
	Imgproc.drawContours(maskCopyTo, counter, -1, Scalar.all(255)); // ��������
	// MatView.imshow(maskCopyTo, "Irregular shape edge");
	final Mat maskFloodFill = new Mat(irrInput.rows() + 2, irrInput.cols() + 2, CvType.CV_8UC1); // ����floodFill������mask���ߴ��ԭͼ��һЩ
	Imgproc.floodFill(maskCopyTo, maskFloodFill, new Point(centerX, centerY), Scalar.all(255), null, Scalar.all(20),
			Scalar.all(20), 4); // ��ˮ��䷨����ڲ�
	// MatView.imshow(maskFloodFill, "Irregular shape��Mask of floodFill"); //
	// ����copyTo������mask
	// MatView.imshow(maskCopyTo, "Irregular shape��Mask of copyTo"); //
	// ����floodFill������mask
	final Mat imgIrregularROI = new Mat();
	irrInput.copyTo(imgIrregularROI, maskCopyTo); // ��ȡ��������״��ROI
	// MatView.imshow(imgIrregularROI, "Irregular shape ROI");
	return imgIrregularROI;
}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:41,代码来源:ROI_Irregular.java

示例8: norm_0_255

import org.opencv.core.Mat; //导入方法依赖的package包/类
/**
 * 图像归一化
* @Title: norm_0_255 
* @Description: TODO(这里用一句话描述这个方法的作用) 
* @param src
* @return
* Mat 
* @throws
 */
public static Mat norm_0_255(Mat src) {
	// 创建和返回一个归一化后的图像矩阵
	Mat dst = new Mat();
	switch(src.channels()) {
		case 1: Core.normalize(src, dst, 0, 255, Core.NORM_MINMAX, CvType.CV_8UC1); break;
		case 3: Core.normalize(src, dst, 0, 255, Core.NORM_MINMAX, CvType.CV_8UC3); break;
		default: src.copyTo(dst);break;
	}
	return dst;
}
 
开发者ID:IaHehe,项目名称:classchecks,代码行数:20,代码来源:ImgprocessUtils.java

示例9: rectangle

import org.opencv.core.Mat; //导入方法依赖的package包/类
/**
 * 
* @Title: rectangle 
* @Description: 以检测的人脸图像区域数组在源图像上画矩形框
* @param mImgSRC
* @param rects
* @return
* Mat 
 */
public static Mat rectangle(Mat mImgSRC, Rect ...rects ) {
	Mat tmp = new Mat();
	mImgSRC.copyTo(tmp);
	for(Rect r : rects) {
		Imgproc.rectangle(tmp, new Point(r.x, r.y), new Point(r.x + r.width, r.y + r.height), new Scalar(0, 0, 255));
	}
	
	return tmp;
}
 
开发者ID:IaHehe,项目名称:classchecks,代码行数:19,代码来源:ImgprocessUtils.java

示例10: irregularQuadrangle

import org.opencv.core.Mat; //导入方法依赖的package包/类
public static Mat irregularQuadrangle(Mat irrInput, Point p1, Point p2, Point p3, Point p4, double shift,
		boolean noULandLRcorner, double ulCornerRatio, double lrCornerRatio) {
	final Mat maskCopyTo = Mat.zeros(irrInput.size(), CvType.CV_8UC1); // ����copyTo������mask����С��ԭͼ����һ��

	final double angle = MathBox.slopeAngle(p1, p2);
	// System.out.println(angle);
	final double sin = Math.sin(angle);
	final double cos = Math.cos(angle);

	// �����ĵ���Ϊ��ʼ����
	final double centerX = (p1.x + p2.x + p3.x + p4.x) / 4;
	final double centerY = (p1.y + p2.y + p3.y + p4.y) / 4;
	final Point cc = new Point(centerX, centerY);

	final List<MatOfPoint> counter = new ArrayList<>();
	final Point aP1raw = new Point(p1.x + shift, p1.y + shift);
	final Point aP2raw = new Point(p2.x - shift, p2.y + shift);
	final Point aP3raw = new Point(p3.x + shift, p3.y - shift);
	final Point aP4raw = new Point(p4.x - shift, p4.y - shift);

	final Point aP1 = MathBox.rotateAroundAPoint(cc, aP1raw, angle);
	final Point aP2 = MathBox.rotateAroundAPoint(cc, aP2raw, angle);
	final Point aP3 = MathBox.rotateAroundAPoint(cc, aP3raw, angle);
	final Point aP4 = MathBox.rotateAroundAPoint(cc, aP4raw, angle);

	if (noULandLRcorner) {
		final Point aP1Lraw = new Point(aP1.x, aP1.y + (aP3.y - aP1.y) * ulCornerRatio);
		final Point aP1Rraw = new Point(aP1.x + (aP2.x - aP1.x) * ulCornerRatio, aP1.y);
		final Point aP4Lraw = new Point(aP4.x - (aP4.x - aP3.x) * lrCornerRatio, aP4.y);
		final Point aP4Rraw = new Point(aP4.x, aP4.y - (aP4.y - aP2.y) * lrCornerRatio);

		final Point aP1L = MathBox.rotateAroundAPoint(cc, aP1Lraw, angle);
		final Point aP1R = MathBox.rotateAroundAPoint(cc, aP1Rraw, angle);
		final Point aP4L = MathBox.rotateAroundAPoint(cc, aP4Lraw, angle);
		final Point aP4R = MathBox.rotateAroundAPoint(cc, aP4Rraw, angle);

		counter.add(new MatOfPoint(aP1L, aP1R, aP2, aP4R, aP4L, aP3)); // ����һ��������Ķ���Σ�û�����ϽǺ����½�
	} else
		counter.add(new MatOfPoint(aP1, aP2, aP4, aP3)); // ����һ��������Ķ����

	// floodFill��mask��width��height�����������ͼ��������������أ��������ᱨ��
	Imgproc.drawContours(maskCopyTo, counter, -1, Scalar.all(255)); // ��������
	MatView.imshow(maskCopyTo, "Irregular shape edge");
	final Mat maskFloodFill = new Mat(irrInput.rows() + 2, irrInput.cols() + 2, CvType.CV_8UC1); // ����floodFill������mask���ߴ��ԭͼ��һЩ
	Imgproc.floodFill(maskCopyTo, maskFloodFill, new Point(centerX, centerY), Scalar.all(255), null, Scalar.all(20),
			Scalar.all(20), 4); // ��ˮ��䷨����ڲ�
	// MatView.imshow(maskFloodFill, "Irregular shape��Mask of floodFill"); //
	// ����copyTo������mask
	// MatView.imshow(maskCopyTo, "Irregular shape��Mask of copyTo"); //
	// ����floodFill������mask
	final Mat imgIrregularROI = new Mat();
	irrInput.copyTo(imgIrregularROI, maskCopyTo); // ��ȡ��������״��ROI
	// MatView.imshow(imgIrregularROI, "Irregular shape ROI");
	return imgIrregularROI;
}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:56,代码来源:ROI_Irregular.java

示例11: initSampleMask

import org.opencv.core.Mat; //导入方法依赖的package包/类
public static void initSampleMask(int height, int width) {
    /**
     * Init sample mask according to `height`, `width`
     */

    // convert apexes to a binary image
    Mat sampleSrc = Mat.zeros(new Size(sampleWindowWidth, sampleWindowHeight), CvType.CV_8UC1);
    Util.fillContour(sampleSrc, sampleWindowContour, new Point(sampleWindowWidth / 2, sampleWindowHeight / 2));

    sampleMask = Mat.zeros(new Size(width, height), CvType.CV_8UC1);

    if (height < sampleWindowHeight || width < sampleWindowWidth) {
        throw new AssertionError(
                "Too small the image(" + width + " cols x" + height +
                        "rows) is to contain a sampling window sized"
                        + sampleWindowWidth + "x" + sampleWindowHeight
        );
    }

    rowOffset = (height - sampleSrc.height()) / 2;
    colOffset = (width - sampleSrc.width()) / 2;

    sampleSrc.copyTo(sampleMask.submat(
            rowOffset, sampleSrc.height() + rowOffset,
            colOffset, sampleSrc.width() + colOffset
    ));


    for (int r = 0; r < height; r += 4) {
        for (int c = 0; c < width; c += 4) {
            if (sampleMask.get(r, c)[0] > 0) {
                samplePixels.add(new Point(c, r));
            }
        }
    }

    // add points in sampleWindowContour for further use
    // now sampleWindowContour shares a same coordinate with
    // tap-detection algorithm
    for (Point p : sampleWindowContour) {
        p.x += colOffset;
        p.y += rowOffset;
    }
}
 
开发者ID:hgs1217,项目名称:Paper-Melody,代码行数:45,代码来源:Sampler.java


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