本文整理匯總了Java中org.opencv.core.Mat.cols方法的典型用法代碼示例。如果您正苦於以下問題:Java Mat.cols方法的具體用法?Java Mat.cols怎麽用?Java Mat.cols使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.opencv.core.Mat
的用法示例。
在下文中一共展示了Mat.cols方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: Mat_to_vector_KeyPoint
import org.opencv.core.Mat; //導入方法依賴的package包/類
public static void Mat_to_vector_KeyPoint(Mat m, List<KeyPoint> kps) {
if (kps == null)
throw new java.lang.IllegalArgumentException("Output List can't be null");
int count = m.rows();
if (CvType.CV_64FC(7) != m.type() || m.cols() != 1)
throw new java.lang.IllegalArgumentException(
"CvType.CV_64FC(7) != m.type() || m.cols()!=1\n" + m);
kps.clear();
double[] buff = new double[7 * count];
m.get(0, 0, buff);
for (int i = 0; i < count; i++) {
kps.add(new KeyPoint((float) buff[7 * i], (float) buff[7 * i + 1], (float) buff[7 * i + 2], (float) buff[7 * i + 3],
(float) buff[7 * i + 4], (int) buff[7 * i + 5], (int) buff[7 * i + 6]));
}
}
示例2: Mat_to_vector_Mat
import org.opencv.core.Mat; //導入方法依賴的package包/類
public static void Mat_to_vector_Mat(Mat m, List<Mat> mats) {
if (mats == null)
throw new java.lang.IllegalArgumentException("mats == null");
int count = m.rows();
if (CvType.CV_32SC2 != m.type() || m.cols() != 1)
throw new java.lang.IllegalArgumentException(
"CvType.CV_32SC2 != m.type() || m.cols()!=1\n" + m);
mats.clear();
int[] buff = new int[count * 2];
m.get(0, 0, buff);
for (int i = 0; i < count; i++) {
long addr = (((long) buff[i * 2]) << 32) | (((long) buff[i * 2 + 1]) & 0xffffffffL);
mats.add(new Mat(addr));
}
}
示例3: Mat_to_vector_Rect
import org.opencv.core.Mat; //導入方法依賴的package包/類
public static void Mat_to_vector_Rect(Mat m, List<Rect> rs) {
if (rs == null)
throw new java.lang.IllegalArgumentException("rs == null");
int count = m.rows();
if (CvType.CV_32SC4 != m.type() || m.cols() != 1)
throw new java.lang.IllegalArgumentException(
"CvType.CV_32SC4 != m.type() || m.rows()!=1\n" + m);
rs.clear();
int[] buff = new int[4 * count];
m.get(0, 0, buff);
for (int i = 0; i < count; i++) {
rs.add(new Rect(buff[4 * i], buff[4 * i + 1], buff[4 * i + 2], buff[4 * i + 3]));
}
}
示例4: toBufferedImage
import org.opencv.core.Mat; //導入方法依賴的package包/類
private Image toBufferedImage(Mat matrix) {
int type = BufferedImage.TYPE_BYTE_GRAY;
if (matrix.channels() > 1) {
type = BufferedImage.TYPE_3BYTE_BGR;
}
int bufferSize = matrix.channels() * matrix.cols() * matrix.rows();
byte[] buffer = new byte[bufferSize];
matrix.get(0, 0, buffer); // 獲取所有的像素點
BufferedImage image = new BufferedImage(matrix.cols(), matrix.rows(), type);
final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
System.arraycopy(buffer, 0, targetPixels, 0, buffer.length);
return image;
}
示例5: Mat_to_vector_int
import org.opencv.core.Mat; //導入方法依賴的package包/類
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
if (is == null)
throw new java.lang.IllegalArgumentException("is == null");
int count = m.rows();
if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
throw new java.lang.IllegalArgumentException(
"CvType.CV_32SC1 != m.type() || m.cols()!=1\n" + m);
is.clear();
int[] buff = new int[count];
m.get(0, 0, buff);
for (int i = 0; i < count; i++) {
is.add(buff[i]);
}
}
示例6: HarrisCorner
import org.opencv.core.Mat; //導入方法依賴的package包/類
void HarrisCorner() {
Mat grayMat = new Mat();
Mat corners = new Mat();
//Converting the image to grayscale
Imgproc.cvtColor(originalMat, grayMat, Imgproc.COLOR_BGR2GRAY);
Mat tempDst = new Mat();
//finding contours
Imgproc.cornerHarris(grayMat, tempDst, 2, 3, 0.04);
//Normalizing harris corner's output
Mat tempDstNorm = new Mat();
Core.normalize(tempDst, tempDstNorm, 0, 255, Core.NORM_MINMAX);
Core.convertScaleAbs(tempDstNorm, corners);
//Drawing corners on a new image
Random r = new Random();
for (int i = 0; i < tempDstNorm.cols(); i++) {
for (int j = 0; j < tempDstNorm.rows(); j++) {
double[] value = tempDstNorm.get(j, i);
if (value[0] > 150)
Imgproc.circle(corners, new Point(i, j), 5, new Scalar(r.nextInt(255)), 2);
}
}
//Converting Mat back to Bitmap
Utils.matToBitmap(corners, currentBitmap);
imageView.setImageBitmap(currentBitmap);
}
示例7: Mat_to_vector_DMatch
import org.opencv.core.Mat; //導入方法依賴的package包/類
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
if (matches == null)
throw new java.lang.IllegalArgumentException("Output List can't be null");
int count = m.rows();
if (CvType.CV_64FC4 != m.type() || m.cols() != 1)
throw new java.lang.IllegalArgumentException(
"CvType.CV_64FC4 != m.type() || m.cols()!=1\n" + m);
matches.clear();
double[] buff = new double[4 * count];
m.get(0, 0, buff);
for (int i = 0; i < count; i++) {
matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3]));
}
}
示例8: Mat_to_vector_float
import org.opencv.core.Mat; //導入方法依賴的package包/類
public static void Mat_to_vector_float(Mat m, List<Float> fs) {
if (fs == null)
throw new java.lang.IllegalArgumentException("fs == null");
int count = m.rows();
if (CvType.CV_32FC1 != m.type() || m.cols() != 1)
throw new java.lang.IllegalArgumentException(
"CvType.CV_32FC1 != m.type() || m.cols()!=1\n" + m);
fs.clear();
float[] buff = new float[count];
m.get(0, 0, buff);
for (int i = 0; i < count; i++) {
fs.add(buff[i]);
}
}
示例9: subspaceProject
import org.opencv.core.Mat; //導入方法依賴的package包/類
public static Mat subspaceProject(Mat W, Mat mean, Mat src) {
int n = src.rows();
int d = src.cols();
Mat X = new Mat();
Mat Y = new Mat();
src.convertTo(X, W.type());
if(!mean.empty()) {
for(int i = 0; i < n; i ++) {
Mat r_i = X.row(i);
Core.subtract(r_i, mean.reshape(1, 1), r_i);
}
}
Core.gemm(X, W, 1.0, new Mat(), 0.0, Y);
return Y;
}
示例10: Mat_to_vector_double
import org.opencv.core.Mat; //導入方法依賴的package包/類
public static void Mat_to_vector_double(Mat m, List<Double> ds) {
if (ds == null)
throw new java.lang.IllegalArgumentException("ds == null");
int count = m.rows();
if (CvType.CV_64FC1 != m.type() || m.cols() != 1)
throw new java.lang.IllegalArgumentException(
"CvType.CV_64FC1 != m.type() || m.cols()!=1\n" + m);
ds.clear();
double[] buff = new double[count];
m.get(0, 0, buff);
for (int i = 0; i < count; i++) {
ds.add(buff[i]);
}
}
示例11: Mat_to_vector_DMatch
import org.opencv.core.Mat; //導入方法依賴的package包/類
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
if (matches == null)
throw new IllegalArgumentException("Output List can't be null");
int count = m.rows();
if (CvType.CV_64FC4 != m.type() || m.cols() != 1)
throw new IllegalArgumentException(
"CvType.CV_64FC4 != m.type() || m.cols()!=1\n" + m);
matches.clear();
double[] buff = new double[4 * count];
m.get(0, 0, buff);
for (int i = 0; i < count; i++) {
matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3]));
}
}
示例12: getMedian
import org.opencv.core.Mat; //導入方法依賴的package包/類
public static int getMedian(Mat mat) {
ArrayList<Mat> listOfMat = new ArrayList<>();
listOfMat.add(mat);
MatOfInt channels = new MatOfInt(0);
Mat mask = new Mat();
Mat hist = new Mat(256, 1, CvType.CV_8UC1);
MatOfInt histSize = new MatOfInt(256);
MatOfFloat ranges = new MatOfFloat(0, 256);
Imgproc.calcHist(listOfMat, channels, mask, hist, histSize, ranges);
double t = mat.rows() * mat.cols() / 2;
double total = 0;
int med = -1;
for (int row = 0; row < hist.rows(); row++) {
double val = hist.get(row, 0)[0];
if ((total <= t) && (total + val >= t)) {
med = row;
break;
}
total += val;
}
// Log.d(TAG, String.format("getMedian() = %d", med));
return med;
}