本文整理汇总了Java中org.opencv.core.Core.minMaxLoc方法的典型用法代码示例。如果您正苦于以下问题:Java Core.minMaxLoc方法的具体用法?Java Core.minMaxLoc怎么用?Java Core.minMaxLoc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opencv.core.Core
的用法示例。
在下文中一共展示了Core.minMaxLoc方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: match
import org.opencv.core.Core; //导入方法依赖的package包/类
public MatchResult match(Mat scene, Mat templ, Method method, Mat img) {
int result_cols = scene.cols() - templ.cols() + 1;
int result_rows = scene.rows() - templ.rows() + 1;
Mat result = new Mat(result_rows, result_cols, CV_32FC1);
Imgproc.matchTemplate(scene, templ, result, method.ordinal());
//Core.normalize(result, result, 0, 1, 32,-1,new Mat());
MinMaxLocResult mmr = Core.minMaxLoc(result);
Point matchLoc;
double maxVal;
if (method.ordinal() == Imgproc.TM_SQDIFF
|| method.ordinal() == Imgproc.TM_SQDIFF_NORMED) {
matchLoc = mmr.minLoc;
maxVal = mmr.minVal;
}
else {
matchLoc = mmr.maxLoc;
maxVal = mmr.maxVal;
}
MatchResult currResult = new MatchResult(matchLoc.x +(templ.cols()/2),matchLoc.y +(templ.rows()/2),0,maxVal);
return currResult;
}
示例2: getBestMatched
import org.opencv.core.Core; //导入方法依赖的package包/类
public static Pair<Point, Double> getBestMatched(Mat tmResult, int matchMethod, float threshold) {
TimingLogger logger = new TimingLogger(LOG_TAG, "best_matched_point");
// FIXME: 2017/11/26 正交化?
// Core.normalize(tmResult, tmResult, 0, 1, Core.NORM_MINMAX, -1, new Mat());
Core.MinMaxLocResult mmr = Core.minMaxLoc(tmResult);
logger.addSplit("minMaxLoc");
double value;
Point pos;
if (matchMethod == Imgproc.TM_SQDIFF || matchMethod == Imgproc.TM_SQDIFF_NORMED) {
pos = mmr.minLoc;
value = -mmr.minVal;
} else {
pos = mmr.maxLoc;
value = mmr.maxVal;
}
logger.addSplit("value:" + value);
logger.dumpToLog();
return new Pair<>(pos, value);
}
示例3: globalAdaptation
import org.opencv.core.Core; //导入方法依赖的package包/类
private static List<Mat> globalAdaptation(Mat b, Mat g, Mat r, int rows, int cols) {
// Calculate Lw & maximum of Lw
Mat Lw = new Mat(rows, cols, r.type());
Core.multiply(r, new Scalar(rParam), r);
Core.multiply(g, new Scalar(gParam), g);
Core.multiply(b, new Scalar(bParam), b);
Core.add(r, g, Lw);
Core.add(Lw, b, Lw);
double LwMax = Core.minMaxLoc(Lw).maxVal; // the maximum luminance value
// Calculate log-average luminance and get global adaptation result
Mat Lw_ = Lw.clone();
Core.add(Lw_, new Scalar(0.001), Lw_);
Core.log(Lw_, Lw_);
double LwAver = Math.exp(Core.sumElems(Lw_).val[0] / (rows * cols));
Mat Lg = Lw.clone();
Core.divide(Lg, new Scalar(LwAver), Lg);
Core.add(Lg, new Scalar(1.0), Lg);
Core.log(Lg, Lg);
Core.divide(Lg, new Scalar(Math.log(LwMax / LwAver + 1.0)), Lg); // Lg is the global adaptation
List<Mat> list = new ArrayList<>();
list.add(Lw);
list.add(Lg);
return list;
}
示例4: buildTemplate
import org.opencv.core.Core; //导入方法依赖的package包/类
/**
* <p>Build a template from a specific eye area previously substracted
* uses detectMultiScale for this area, then uses minMaxLoc method to
* detect iris from the detected eye</p>
*
* @param area Preformatted Area
* @param size minimum iris size
* @param grayMat image in gray
* @param rgbaMat image in color
* @param detectorEye Haar Cascade classifier
* @return built template
*/
@NonNull
private static Mat buildTemplate(Rect area, final int size,
@NonNull Mat grayMat,
@NonNull Mat rgbaMat,
CascadeClassifier detectorEye) {
Mat template = new Mat();
Mat graySubMatEye = grayMat.submat(area);
MatOfRect eyes = new MatOfRect();
Rect eyeTemplate;
detectorEye.detectMultiScale(graySubMatEye, eyes, 1.15, 2,
Objdetect.CASCADE_FIND_BIGGEST_OBJECT
| Objdetect.CASCADE_SCALE_IMAGE, new Size(EYE_MIN_SIZE, EYE_MIN_SIZE),
new Size());
Rect[] eyesArray = eyes.toArray();
if (eyesArray.length > 0) {
Rect e = eyesArray[0];
e.x = area.x + e.x;
e.y = area.y + e.y;
Rect eyeRectangle = getEyeArea((int) e.tl().x,
(int) (e.tl().y + e.height * 0.4),
e.width,
(int) (e.height * 0.6));
graySubMatEye = grayMat.submat(eyeRectangle);
Mat rgbaMatEye = rgbaMat.submat(eyeRectangle);
Core.MinMaxLocResult minMaxLoc = Core.minMaxLoc(graySubMatEye);
FaceDrawerOpenCV.drawIrisCircle(rgbaMatEye, minMaxLoc);
Point iris = new Point();
iris.x = minMaxLoc.minLoc.x + eyeRectangle.x;
iris.y = minMaxLoc.minLoc.y + eyeRectangle.y;
eyeTemplate = getEyeArea((int) iris.x - size / 2,
(int) iris.y
- size / 2, size, size);
FaceDrawerOpenCV.drawEyeRectangle(eyeTemplate, rgbaMat);
template = (grayMat.submat(eyeTemplate)).clone();
}
return template;
}
示例5: adjustment
import org.opencv.core.Core; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private static Mat adjustment(Mat alpha, double a) {
double b = Core.minMaxLoc(alpha).maxVal;
int rows = alpha.rows();
int cols = alpha.cols();
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
//double val = alpha.get(i, j)[0];
alpha.put(i, j, (2 * Math.atan(a * alpha.get(i, j)[0] / b) / Math.PI * b));
}
}
return alpha;
}
示例6: findImage
import org.opencv.core.Core; //导入方法依赖的package包/类
private ImageFinderResult findImage(Mat sourceMat, Mat templateMat, double desiredAccuracy) {
if (sourceMat.width() < templateMat.width() || sourceMat.height() < templateMat.height()) {
throw new UnsupportedOperationException("The template image is larger than the source image. Ensure that the width and/or height of the image you are trying to find do not exceed the dimensions of the source image.");
}
Mat result = new Mat(sourceMat.rows() - templateMat.rows() + 1, sourceMat.rows() - templateMat.rows() + 1, CvType.CV_32FC1);
int intMatchingMethod;
switch (this.matchingMethod) {
case MM_CORELLATION_COEFF:
intMatchingMethod = Imgproc.TM_CCOEFF_NORMED;
break;
case MM_CROSS_CORELLATION:
intMatchingMethod = Imgproc.TM_CCORR_NORMED;
break;
default:
intMatchingMethod = Imgproc.TM_SQDIFF_NORMED;
}
Imgproc.matchTemplate(sourceMat, templateMat, result, intMatchingMethod);
MinMaxLocResult minMaxLocRes = Core.minMaxLoc(result);
double accuracy = 0;
Point location = null;
if (this.matchingMethod == MatchingMethod.MM_SQUARE_DIFFERENCE) {
accuracy = 1 - minMaxLocRes.minVal;
location = minMaxLocRes.minLoc;
} else {
accuracy = minMaxLocRes.maxVal;
location = minMaxLocRes.maxLoc;
}
if (accuracy < desiredAccuracy) {
throw new ImageNotFoundException(
String.format(
"Failed to find template image in the source image. The accuracy was %.2f and the desired accuracy was %.2f",
accuracy,
desiredAccuracy),
new Rectangle((int) location.x, (int) location.y, templateMat.width(), templateMat.height()),
accuracy);
}
if (!minMaxLocResultIsValid(minMaxLocRes)) {
throw new ImageNotFoundException(
"Image find result (MinMaxLocResult) was invalid. This usually happens when the source image is covered in one solid color.",
null,
null);
}
Rectangle foundRect = new Rectangle(
(int) location.x,
(int) location.y,
templateMat.width(),
templateMat.height());
return new ImageFinderResult(foundRect, accuracy);
}