本文整理匯總了Java中org.opencv.core.Mat.size方法的典型用法代碼示例。如果您正苦於以下問題:Java Mat.size方法的具體用法?Java Mat.size怎麽用?Java Mat.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.opencv.core.Mat
的用法示例。
在下文中一共展示了Mat.size方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: analyzeFrame
import org.opencv.core.Mat; //導入方法依賴的package包/類
/**
* Analyze the current frame using the selected analysis method, using custom color blob detectors
*
* @param redDetector Red color blob detector
* @param blueDetector Blue color blob detector
* @param img Image to analyze
* @param gray Grayscale image to analyze
* @param orientation Screen orientation compensation, given by the android.Sensors class
* @return Beacon analysis class
*/
public BeaconAnalysis analyzeFrame(ColorBlobDetector redDetector, ColorBlobDetector blueDetector, Mat img, Mat gray, ScreenOrientation orientation) {
if (this.bounds == null)
this.bounds = new Rectangle(img.size());
switch (method) {
case REALTIME:
blueDetector.process(img);
redDetector.process(img);
return BeaconAnalyzer.analyze_REALTIME(redDetector.getContours(), blueDetector.getContours(), img, orientation, this.debug);
case FAST:
case DEFAULT:
default:
return BeaconAnalyzer.analyze_FAST(redDetector, blueDetector, img, gray, orientation, this.bounds, this.debug);
case COMPLEX:
blueDetector.process(img);
redDetector.process(img);
return BeaconAnalyzer.analyze_COMPLEX(redDetector.getContours(), blueDetector.getContours(), img, gray, orientation, this.bounds, this.debug);
}
}
示例2: makeScale
import org.opencv.core.Mat; //導入方法依賴的package包/類
/**
* Scales an image to an approximate size. The scale will always be equal
* on the x and y axis, regardless of the approxSize.
*
* @param img The image
* @param approxSize The target size
* @param maximize If maximize is true, then if the approxSize aspect ratio
* does not match the target, then the largest possible image
* would be used. If false (default), the the smallest image
* would be used.
* @param integerScale If true (default), then only integer scale factors would be used.
* Otherwise, any scale factor can be used.
*/
private static double makeScale(Mat img, Size approxSize, boolean maximize, boolean integerScale) {
Size imageSize = img.size();
double ratioWidth = approxSize.width / imageSize.width;
double ratioHeight = approxSize.height / imageSize.height;
double ratio = maximize ? Math.max(ratioWidth, ratioHeight) : Math.min(ratioWidth, ratioHeight);
if (MathUtil.equal(ratio, 1))
return 1;
if (integerScale) {
//The scale factor is always greater than 1
double scale = (ratio < 1) ? 1 / ratio : ratio;
//If you are actually increasing the size of the object, use ceiling()
//Otherwise, use floor()
scale = maximize ^ (ratio < 1) ? Math.ceil(scale) : Math.floor(scale);
//Get the actual ratio again
return (ratio < 1) ? 1 / scale : scale;
} else {
return ratio;
}
}
示例3: reconstructFace
import org.opencv.core.Mat; //導入方法依賴的package包/類
/**
*
* @Title: reconstructFace
* @Description: 從輸入的預處理圖像在人臉模型中重構人臉
* @param model 包含預處理的人臉模型
* @param preprocessedFace 輸入的預處理過的圖像
* @return
* Mat
* @throws
*/
public static Mat reconstructFace(BasicFaceRecognizer model, Mat preprocessedFace){
try {
// 獲取每個人臉的特征值
Mat eigenvectors = model.getEigenVectors();
// 獲取平均人臉
Mat averageFaceRow = model.getMean();
int faceHeight = preprocessedFace.rows();
// subspaceProject將人臉圖像投影到特征空間
Mat projection = subspaceProject(eigenvectors, averageFaceRow, preprocessedFace.reshape(1, 1));
// subspaceReconstruct從特征空間重構圖像
Mat reconstructionRow = subspaceReconstruct(eigenvectors, averageFaceRow, projection);
Mat reconstructionMat = reconstructionRow.reshape(1, faceHeight);
Mat reconstructedFace = new Mat(reconstructionMat.size(), CvType.CV_8U);
reconstructionMat.convertTo(reconstructedFace, CvType.CV_8U, 1, 0);
return reconstructedFace;
} catch(CvException e) {
e.printStackTrace();
}
return null;
}
示例4: resize
import org.opencv.core.Mat; //導入方法依賴的package包/類
private static void resize(Mat img, Size size) {
int interpolation;
if (MathUtil.equal(size.area(), img.size().area()))
return;
else if (size.width > img.size().width && size.height > img.size().height)
interpolation = Imgproc.CV_INTER_CUBIC; //enlarge image
else if (size.width < img.size().width && size.height < img.size().height)
interpolation = Imgproc.CV_INTER_AREA; //shrink image
else
interpolation = Imgproc.CV_INTER_LINEAR; //not entirely sure, so use safe option
Imgproc.resize(img, img, size, 0, 0, interpolation);
}
示例5: resize
import org.opencv.core.Mat; //導入方法依賴的package包/類
public static double resize(Mat im, int height) {
/*
@return: a double indicating the shrink ratio
= new height / old height
*/
Size size = im.size();
int width = (int) (height * size.width / size.height);
Imgproc.resize(im, im, new Size(width, height));
return (double) height / size.height;
}
示例6: Hist
import org.opencv.core.Mat; //導入方法依賴的package包/類
public static Mat Hist(Mat srcImage){
Mat dstImage = new Mat();
Mat grayImage = new Mat();
Mat dilateImage = new Mat();
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat lut= new Mat(256, 1, CvType.CV_8UC1);
Imgproc.cvtColor(srcImage, grayImage, Imgproc.COLOR_BGR2GRAY);
ArrayList<Mat> histsSource = new ArrayList<Mat>();
histsSource.add(grayImage);
Mat hist = new Mat();
Imgproc.calcHist(histsSource, new MatOfInt(0), new Mat(), hist, new MatOfInt(256), new MatOfFloat(0f, 256f));
int min=0,max=0;
for (int i=0;i<hist.size().height;i++){
if (hist.get(i,0)[0]>0)
{ min=i;
break;}
}
for (int i=(int)(hist.size().height)-1;i>=0;i--){
if (hist.get(i,0)[0]>0)
{ max=i;
break;}
}
for (int i=0;i<hist.size().height;i++){
if (i<min){lut.put(i,0,0.0);}
else if (i>max){lut.put(i,0,255.0);}
else {lut.put(i,0,255.0*(i-min)/(max-min)+0.5);}
}
//for (int i=0;i<lut.size().height;i++){
//System.out.println(lut.get(i,0)[0]);}
Core.LUT(grayImage,lut,grayImage);
return grayImage;
}
示例7: process
import org.opencv.core.Mat; //導入方法依賴的package包/類
private void process(Mat f)
{
Mat gen = new Mat();
if (flipActive) Core.flip(f, f, 1);
Imgproc.cvtColor(f, gen, Imgproc.COLOR_BGR2RGB);
if (weirdRenderActive) Imgproc.cvtColor(gen, gen, Imgproc.COLOR_HSV2RGB);
Point mid = new Point(gen.size().width/2, gen.size().height/2);
midPoint = gen.get((int)mid.y, (int)mid.x);
Imgproc.circle(gen, mid, 5, new Scalar(255-(int)(midPoint[0]), 255-(int)(midPoint[1]), 255-(int)(midPoint[2])), 2);
Imgproc.cvtColor(gen, f, Imgproc.COLOR_RGB2BGR);
}
示例8: example
import org.opencv.core.Mat; //導入方法依賴的package包/類
private void example() {
RenderScript mRS = RenderScript.create(this);
// Loads input image
Bitmap inputBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.houseimage);
// Puts input image inside an OpenCV mat
Mat inputMat = new Mat();
Utils.bitmapToMat(inputBitmap, inputMat);
Mat outputMat = new Mat(inputMat.size(), inputMat.type());
// Testing bitmap, used to test that the OpenCV mat actually has bitmap data inside
Bitmap initialBitmap = Bitmap.createBitmap(inputMat.width(), inputMat.height(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(inputMat, initialBitmap);
// Retrieve OpenCV mat data address
long inputMatDataAddress = inputMat.dataAddr();
long outputMatDataAddress = outputMat.dataAddr();
// Creates a RS type that matches the input mat one.
Element element = Element.RGBA_8888(mRS);
Type.Builder tb = new Type.Builder(mRS, element);
tb.setX(inputMat.width());
tb.setY(inputMat.height());
Type inputMatType = tb.create();
// Creates a RenderScript allocation that uses directly the OpenCV input mat address
Allocation inputAllocation = createTypedAllocationWithDataPointer(mRS, inputMatType, inputMatDataAddress);
Allocation outputAllocation = createTypedAllocationWithDataPointer(mRS, inputMatType, outputMatDataAddress);
// Define a simple convolve script
// Note: here, ANY kernel can be applied!
ScriptIntrinsicConvolve3x3 convolve3x3 = ScriptIntrinsicConvolve3x3.create(mRS, element);
float convolveCoefficients[] = new float[9];
convolveCoefficients[0] = 1;
convolveCoefficients[2] = 1;
convolveCoefficients[5] = 1;
convolveCoefficients[6] = 1;
convolveCoefficients[8] = 1;
convolve3x3.setCoefficients(convolveCoefficients);
convolve3x3.setInput(inputAllocation);
convolve3x3.forEach(outputAllocation);
mRS.finish();
// Converts the result to a bitmap
Bitmap cvOutputBitmap = Bitmap.createBitmap(outputMat.width(), outputMat.height(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(outputMat, cvOutputBitmap);
// Testing bitmap, used to test the RenderScript ouput allocation contents
// Note: it is placed here because the copyTo function clears the input buffer
Bitmap rsOutputBitmap = Bitmap.createBitmap(outputMat.width(), outputMat.height(), Bitmap.Config.ARGB_8888);
outputAllocation.copyTo(rsOutputBitmap);
// Testing bitmap, used to test that RenderScript input allocation pointed to the OpenCV mat
// Note: it is placed here because the copyTo function clears the input buffer
Bitmap rsInitialBitmap = Bitmap.createBitmap(inputMat.width(), inputMat.height(), Bitmap.Config.ARGB_8888);
inputAllocation.copyTo(rsInitialBitmap);
// Display input and output
ImageView originalImageIV = (ImageView) findViewById(R.id.imageView);
ImageView inputRSImageIV = (ImageView) findViewById(R.id.imageView2);
ImageView outputRSImageIV = (ImageView) findViewById(R.id.imageView3);
ImageView outputCVIV = (ImageView) findViewById(R.id.imageView4);
originalImageIV.setImageBitmap(initialBitmap);
inputRSImageIV.setImageBitmap(rsInitialBitmap);
outputRSImageIV.setImageBitmap(rsOutputBitmap);
outputCVIV.setImageBitmap(cvOutputBitmap);
}
示例9: thinning
import org.opencv.core.Mat; //導入方法依賴的package包/類
private Mat thinning(Mat img) {
Mat thinned = new Mat(img.size(), CvType.CV_8UC1);
Imgproc.threshold(img, thinned, 0, 255, Imgproc.THRESH_OTSU);
Thinning t = new Thinning();
thinned = t.doJaniThinning(thinned);
return thinned;
}