Java Code Examples for org.opencv.core.Core#meanStdDev()

The following examples show how to use org.opencv.core.Core#meanStdDev() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: OptimizedImageEnhance   File: AirlightEstimate.java    License: MIT License 5 votes vote down vote up
private static double calculateScore(Mat im) {
	MatOfDouble mean = new MatOfDouble();
	MatOfDouble std = new MatOfDouble();
	Core.meanStdDev(im, mean, std);
	double[] means = mean.get(0, 0);
	double[] stds = std.get(0, 0);
	double score = 0.0;
	for (int i = 0; i < means.length; i++) score += means[i] - stds[i];
	return score;
}
 
Example 2
Source Project: OpenTLDAndroid   File: Tld.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Output: resized zero-mean patch/pattern
 * @param inImg INPUT, outPattern OUTPUT
 * @return stdev
 */
private static double resizeZeroMeanStdev(final Mat inImg, Mat outPattern, int patternSize){
	if(inImg == null || outPattern == null){
		return -1;
	}
	
	Imgproc.resize(inImg, outPattern, new Size(patternSize, patternSize));
	final MatOfDouble mean = new MatOfDouble();
	final MatOfDouble stdev = new MatOfDouble();
	Core.meanStdDev(outPattern, mean, stdev);
	outPattern.convertTo(outPattern, CvType.CV_32F);
	Core.subtract(outPattern, new Scalar(mean.toArray()[0]), outPattern);
	
	return stdev.toArray()[0];
}
 
Example 3
/**
 * @param input - Input mat
 * @return - Difference from perfect score
 */
@Override
public double calculateScore(Mat input) {
    Core.meanStdDev(input, mean, std);
    return MathFTC.mean(std.get(0,0));
}
 
Example 4
Source Project: OpenTLDAndroid   File: Tld.java    License: Apache License 2.0 4 votes vote down vote up
public void init(Mat frame1, Rect trackedBox) {
	// get Bounding boxes
	if(Math.min(trackedBox.width, trackedBox.height) < _params.min_win) {
		throw new IllegalArgumentException("Provided trackedBox: " + trackedBox + " is too small (min " + _params.min_win + ")");
	}
	_grid = new Grid(frame1, trackedBox, _params.min_win);
	Log.i(Util.TAG, "Init Created " + _grid.getSize() + " bounding boxes.");
	_grid.updateGoodBadBoxes(trackedBox, _params.num_closest_init);
	
	_iiRows = frame1.rows();
	_iiCols = frame1.cols();
	_iisum.create(_iiRows, _iiCols, CvType.CV_32F);
	_iisqsum.create(_iiRows, _iiCols, CvType.CV_64F);
	
	// correct bounding box
	_lastbox = _grid.getBestBox();
	
	_classifierFern.init(_grid.getTrackedBoxScales(), _rng);
	
	
	// generate DATA
	// generate POSITIVE DATA
	generatePositiveData(frame1, _params.num_warps_init, _grid);
	
	// Set variance threshold
	MatOfDouble stddev = new MatOfDouble();
	Core.meanStdDev(frame1.submat(_grid.getBestBox()), new MatOfDouble(), stddev);
	updateIntegralImgs(frame1);
	// this is directly half of the variance of the initial box, which will be used the the 1st stage of the classifier
	_var = (float)Math.pow(stddev.toArray()[0], 2d) * 0.5f;
	// check variance
	final double checkVar = Util.getVar(_grid.getBestBox(), _iisumJava, _iisqsumJava, _iiCols) * 0.5;
	Log.i(Util.TAG, "Variance: " + _var + " / Check variance: " + checkVar);
	
	
	// generate NEGATIVE DATA
	final Pair<List<Pair<int[], Boolean>>, List<Mat>> negData = generateNegativeData(frame1);
	
	// Split Negative Ferns <features, labels=false> into Training and Testing sets (they are already shuffled)
	final int nFernsSize = negData.first.size();
	final List<Pair<int[], Boolean>> nFernsTest = new ArrayList<Pair<int[], Boolean>>(negData.first.subList(0, nFernsSize/2));
	final List<Pair<int[], Boolean>> nFerns = new ArrayList<Pair<int[], Boolean>>(negData.first.subList(nFernsSize/2, nFernsSize));
	
	// Split Negative NN Examples into Training and Testing sets
	final int nExSize = negData.second.size();
	final List<Mat> nExamplesTest = new ArrayList<Mat>(negData.second.subList(0, nExSize/2));
	_nExamples = new ArrayList<Mat>(negData.second.subList(nExSize/2, nExSize));

	
	//MERGE Negative Data with Positive Data and shuffle it
	final List<Pair<int[], Boolean>> fernsData = new ArrayList<Pair<int[], Boolean>>(_pFerns);
	fernsData.addAll(nFerns);
	Collections.shuffle(fernsData);
	
	// TRAINING
	Log.i(Util.TAG, "Init Start Training with " + fernsData.size() + " ferns, " 
	+ _nExamples.size() + " nExamples, " + nFernsTest.size() + " nFernsTest, " + nExamplesTest.size() + " nExamplesTest");
	_classifierFern.trainF(fernsData, 10);
	_classifierNN.trainNN(_pExample, _nExamples);
	// Threshold evaluation on testing sets
	_classifierFern.evaluateThreshold(nFernsTest);
	_classifierNN.evaluateThreshold(nExamplesTest);
}