use of org.bytedeco.opencv.opencv_core.Mat in project karate by karatelabs.
the class OpenCvUtils method rescale.
public static Mat rescale(Mat mat, double scale) {
Mat resized = new Mat();
resize(mat, resized, new Size(), scale, scale, CV_INTER_AREA);
return resized;
}
use of org.bytedeco.opencv.opencv_core.Mat in project karate by karatelabs.
the class Tesseract method process.
public void process(Region region, boolean negative) {
BufferedImage bi = region.captureGreyScale();
if (region.robot.highlight) {
region.highlight(region.robot.highlightDuration);
}
Mat mat = OpenCvUtils.toMat(bi);
process(mat, negative);
}
use of org.bytedeco.opencv.opencv_core.Mat in project qupath by qupath.
the class OpenCVTools method getGaussianDerivKernel.
/**
* Get filter coefficients for a 1D Gaussian (derivative) kernel.
*
* @param sigma Gaussian sigma
* @param order order of the derivative: 0, ('standard' Gaussian filter), 1 (first derivative) or 2 (second derivative)
* @param doColumn if true, return coefficients as a column vector rather than a row vector (default)
* @return
*/
public static Mat getGaussianDerivKernel(double sigma, int order, boolean doColumn) {
int n = (int) (sigma * 4);
int len = n * 2 + 1;
double[] kernel = getGaussianDeriv(sigma, order, len);
Mat mat;
if (doColumn)
mat = new Mat(1, kernel.length, opencv_core.CV_64F);
else
mat = new Mat(kernel.length, 1, opencv_core.CV_64F);
DoubleIndexer indexer = mat.createIndexer();
indexer.put(0L, kernel);
indexer.release();
return mat;
}
use of org.bytedeco.opencv.opencv_core.Mat in project qupath by qupath.
the class OpenCVTools method splitChannels.
/**
* Split channels from a {@link Mat}.
* May be more convenient than OpenCV's built-in approach.
*
* @param mat
* @return a list of {@link Mat}, containing each split channel in order
*/
public static List<Mat> splitChannels(Mat mat) {
var list = new ArrayList<Mat>();
var channels = mat.channels();
for (int c = 0; c < channels; c++) {
var temp = new Mat();
opencv_core.extractChannel(mat, temp, c);
list.add(temp);
}
return list;
// This code appeared to give the occasional crazy result (perhaps followed by a segfault?)
// var matvec = new MatVector();
// opencv_core.split(mat, matvec);
// return Arrays.asList(matvec.get());
}
use of org.bytedeco.opencv.opencv_core.Mat in project qupath by qupath.
the class OpenCVTools method labelsToPoints.
private static List<IndexedPixel> labelsToPoints(Mat mat) {
if (mat.channels() != 1)
throw new IllegalArgumentException("labelsToPoints requires a single-channel mat, but input has " + mat.channels() + " channels");
int w = mat.cols();
int h = mat.rows();
var pixels = new ArrayList<IndexedPixel>();
try (IntIndexer idx = mat.createIndexer()) {
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int lab = idx.get(y, x);
if (lab != 0) {
pixels.add(new IndexedPixel(x, y, lab));
}
}
}
}
// Group by label
var groups = pixels.stream().collect(Collectors.groupingBy(p -> p.value));
return groups.values().stream().map(l -> closestToCentroid(l)).collect(Collectors.toList());
}
Aggregations