本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}