本文整理匯總了Java中org.opencv.core.MatOfInt.size方法的典型用法代碼示例。如果您正苦於以下問題:Java MatOfInt.size方法的具體用法?Java MatOfInt.size怎麽用?Java MatOfInt.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.opencv.core.MatOfInt
的用法示例。
在下文中一共展示了MatOfInt.size方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: filterContours
import org.opencv.core.MatOfInt; //導入方法依賴的package包/類
/**
* Filters out contours that do not meet certain criteria.
*
* @param inputContours
* is the input list of contours
* @param output
* is the the output list of contours
* @param minArea
* is the minimum area of a contour that will be kept
* @param minPerimeter
* is the minimum perimeter of a contour that will be kept
* @param minWidth
* minimum width of a contour
* @param maxWidth
* maximum width
* @param minHeight
* minimum height
* @param maxHeight
* maximimum height
* @param Solidity
* the minimum and maximum solidity of a contour
* @param minVertexCount
* minimum vertex Count of the contours
* @param maxVertexCount
* maximum vertex Count
* @param minRatio
* minimum ratio of width to height
* @param maxRatio
* maximum ratio of width to height
*/
private void filterContours(List<MatOfPoint> inputContours, double minArea, double minPerimeter, double minWidth,
double maxWidth, double minHeight, double maxHeight, double[] solidity, double maxVertexCount,
double minVertexCount, double minRatio, double maxRatio, List<MatOfPoint> output) {
final MatOfInt hull = new MatOfInt();
output.clear();
// operation
for (int i = 0; i < inputContours.size(); i++) {
final MatOfPoint contour = inputContours.get(i);
final Rect bb = Imgproc.boundingRect(contour);
if (bb.width < minWidth || bb.width > maxWidth)
continue;
if (bb.height < minHeight || bb.height > maxHeight)
continue;
final double area = Imgproc.contourArea(contour);
if (area < minArea)
continue;
if (Imgproc.arcLength(new MatOfPoint2f(contour.toArray()), true) < minPerimeter)
continue;
Imgproc.convexHull(contour, hull);
MatOfPoint mopHull = new MatOfPoint();
mopHull.create((int) hull.size().height, 1, CvType.CV_32SC2);
for (int j = 0; j < hull.size().height; j++) {
int index = (int) hull.get(j, 0)[0];
double[] point = new double[] { contour.get(index, 0)[0], contour.get(index, 0)[1] };
mopHull.put(j, 0, point);
}
final double solid = 100 * area / Imgproc.contourArea(mopHull);
if (solid < solidity[0] || solid > solidity[1])
continue;
if (contour.rows() < minVertexCount || contour.rows() > maxVertexCount)
continue;
final double ratio = bb.width / (double) bb.height;
if (ratio < minRatio || ratio > maxRatio)
continue;
output.add(contour);
}
}
示例2: filterContours
import org.opencv.core.MatOfInt; //導入方法依賴的package包/類
/**
* Filters out contours that do not meet certain criteria.
* @param inputContours is the input list of contours
* @param output is the the output list of contours
* @param minArea is the minimum area of a contour that will be kept
* @param minPerimeter is the minimum perimeter of a contour that will be kept
* @param minWidth minimum width of a contour
* @param maxWidth maximum width
* @param minHeight minimum height
* @param maxHeight maximimum height
* @param Solidity the minimum and maximum solidity of a contour
* @param minVertexCount minimum vertex Count of the contours
* @param maxVertexCount maximum vertex Count
* @param minRatio minimum ratio of width to height
* @param maxRatio maximum ratio of width to height
*/
private void filterContours(List<MatOfPoint> inputContours, double minArea,
double minPerimeter, double minWidth, double maxWidth, double minHeight, double
maxHeight, double[] solidity, double maxVertexCount, double minVertexCount, double
minRatio, double maxRatio, List<MatOfPoint> output) {
final MatOfInt hull = new MatOfInt();
output.clear();
//operation
for (int i = 0; i < inputContours.size(); i++) {
final MatOfPoint contour = inputContours.get(i);
final Rect bb = Imgproc.boundingRect(contour);
if (bb.width < minWidth || bb.width > maxWidth) continue;
if (bb.height < minHeight || bb.height > maxHeight) continue;
final double area = Imgproc.contourArea(contour);
if (area < minArea) continue;
if (Imgproc.arcLength(new MatOfPoint2f(contour.toArray()), true) < minPerimeter) continue;
Imgproc.convexHull(contour, hull);
MatOfPoint mopHull = new MatOfPoint();
mopHull.create((int) hull.size().height, 1, CvType.CV_32SC2);
for (int j = 0; j < hull.size().height; j++) {
int index = (int)hull.get(j, 0)[0];
double[] point = new double[] { contour.get(index, 0)[0], contour.get(index, 0)[1]};
mopHull.put(j, 0, point);
}
final double solid = 100 * area / Imgproc.contourArea(mopHull);
if (solid < solidity[0] || solid > solidity[1]) continue;
if (contour.rows() < minVertexCount || contour.rows() > maxVertexCount) continue;
final double ratio = bb.width / (double)bb.height;
if (ratio < minRatio || ratio > maxRatio) continue;
output.add(contour);
}
}
示例3: scoreContour
import org.opencv.core.MatOfInt; //導入方法依賴的package包/類
/**
* Score contour based on a variety of factors
* @param mop contour to score
* @return contour score (range from 0 to infinity?)
*/
private double scoreContour(MatOfPoint mop) {
// Score on solidity -- ideally find 100% solid rectangle
final MatOfInt hull = new MatOfInt(); // is this expensive?
final double area = Imgproc.contourArea(mop);
Imgproc.convexHull(mop, hull);
MatOfPoint mopHull = new MatOfPoint();
mopHull.create((int) hull.size().height, 1, CvType.CV_32SC2);
for (int j = 0; j < hull.size().height; j++) {
int index = (int)hull.get(j, 0)[0];
double[] point = new double[] { mop.get(index, 0)[0], mop.get(index, 0)[1]};
mopHull.put(j, 0, point);
}
final double solid = 100 * area / Imgproc.contourArea(mopHull);
double scoreSolidity = solid;
// Score aspect ratio -- exact ratio is 0.4
final Rect bb = Imgproc.boundingRect(mop);
final double ratio = bb.width / (double)bb.height;
final double targetRatio = 0.4;
final double minRatio = 0.0;
final double maxRatio = 1.0;
double scoreAspectRatio = 0;
if (ratio < minRatio || ratio > maxRatio) {
scoreAspectRatio = 0;
} else {
if (ratio > targetRatio) {
scoreAspectRatio = 1 - (ratio - targetRatio) / (maxRatio - targetRatio);
} else {
scoreAspectRatio = 1 - (targetRatio - ratio) / (targetRatio - minRatio);
}
scoreAspectRatio *= 100;
}
// Compute final score
double score = scoreSolidity + scoreAspectRatio;
return score;
}
示例4: filterContours
import org.opencv.core.MatOfInt; //導入方法依賴的package包/類
/**
* Filters out contours that do not meet certain criteria.
*
* @param inputContours
* is the input list of contours
* @param output
* is the the output list of contours
* @param minArea
* is the minimum area of a contour that will be kept
* @param minPerimeter
* is the minimum perimeter of a contour that will be kept
* @param minWidth
* minimum width of a contour
* @param maxWidth
* maximum width
* @param minHeight
* minimum height
* @param maxHeight
* maximimum height
* @param Solidity
* the minimum and maximum solidity of a contour
* @param minVertexCount
* minimum vertex Count of the contours
* @param maxVertexCount
* maximum vertex Count
* @param minRatio
* minimum ratio of width to height
* @param maxRatio
* maximum ratio of width to height
*/
private void filterContours (List<MatOfPoint> inputContours,
double minArea,
double minPerimeter, double minWidth, double maxWidth,
double minHeight, double maxHeight, double[] solidity,
double maxVertexCount, double minVertexCount, double minRatio,
double maxRatio, List<MatOfPoint> output)
{
final MatOfInt hull = new MatOfInt();
output.clear();
// operation
for (int i = 0; i < inputContours.size(); i++)
{
final MatOfPoint contour = inputContours.get(i);
final Rect bb = Imgproc.boundingRect(contour);
if (bb.width < minWidth || bb.width > maxWidth)
continue;
if (bb.height < minHeight || bb.height > maxHeight)
continue;
final double area = Imgproc.contourArea(contour);
if (area < minArea)
continue;
if (Imgproc.arcLength(new MatOfPoint2f(contour.toArray()),
true) < minPerimeter)
continue;
Imgproc.convexHull(contour, hull);
MatOfPoint mopHull = new MatOfPoint();
mopHull.create((int) hull.size().height, 1, CvType.CV_32SC2);
for (int j = 0; j < hull.size().height; j++)
{
int index = (int) hull.get(j, 0)[0];
double[] point = new double[]
{contour.get(index, 0)[0], contour.get(index, 0)[1]};
mopHull.put(j, 0, point);
}
final double solid = 100 * area / Imgproc.contourArea(mopHull);
if (solid < solidity[0] || solid > solidity[1])
continue;
if (contour.rows() < minVertexCount
|| contour.rows() > maxVertexCount)
continue;
final double ratio = bb.width / (double) bb.height;
if (ratio < minRatio || ratio > maxRatio)
continue;
output.add(contour);
}
}
示例5: filterContours
import org.opencv.core.MatOfInt; //導入方法依賴的package包/類
/**
* Filters out contours that do not meet certain criteria.
*
* @param inputContours
* is the input list of contours
* @param output
* is the the output list of contours
* @param minArea
* is the minimum area of a contour that will be kept
* @param minPerimeter
* is the minimum perimeter of a contour that will be kept
* @param minWidth
* minimum width of a contour
* @param maxWidth
* maximum width
* @param minHeight
* minimum height
* @param maxHeight
* maximimum height
* @param Solidity
* the minimum and maximum solidity of a contour
* @param minVertexCount
* minimum vertex Count of the contours
* @param maxVertexCount
* maximum vertex Count
* @param minRatio
* minimum ratio of width to height
* @param maxRatio
* maximum ratio of width to height
*/
private void filterContours(List<MatOfPoint> inputContours, double minArea, double minPerimeter, double minWidth,
double maxWidth, double minHeight, double maxHeight, double[] solidity, double maxVertexCount,
double minVertexCount, double minRatio, double maxRatio, List<MatOfPoint> output) {
final MatOfInt hull = new MatOfInt();
output.clear();
// operation
for (int i = 0; i < inputContours.size(); i++) {
final MatOfPoint contour = inputContours.get(i);
final Rect bb = Imgproc.boundingRect(contour);
if (bb.width < minWidth || bb.width > maxWidth) {
continue;
}
if (bb.height < minHeight || bb.height > maxHeight) {
continue;
}
final double area = Imgproc.contourArea(contour);
if (area < minArea) {
continue;
}
if (Imgproc.arcLength(new MatOfPoint2f(contour.toArray()), true) < minPerimeter) {
continue;
}
Imgproc.convexHull(contour, hull);
MatOfPoint mopHull = new MatOfPoint();
mopHull.create((int) hull.size().height, 1, CvType.CV_32SC2);
for (int j = 0; j < hull.size().height; j++) {
int index = (int) hull.get(j, 0)[0];
double[] point = new double[] { contour.get(index, 0)[0], contour.get(index, 0)[1] };
mopHull.put(j, 0, point);
}
final double solid = 100 * area / Imgproc.contourArea(mopHull);
if (solid < solidity[0] || solid > solidity[1]) {
continue;
}
if (contour.rows() < minVertexCount || contour.rows() > maxVertexCount) {
continue;
}
final double ratio = bb.width / (double) bb.height;
if (ratio < minRatio || ratio > maxRatio) {
continue;
}
output.add(contour);
}
}