本文整理匯總了Java中org.opencv.core.Rect類的典型用法代碼示例。如果您正苦於以下問題:Java Rect類的具體用法?Java Rect怎麽用?Java Rect使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Rect類屬於org.opencv.core包,在下文中一共展示了Rect類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createParticleReports
import org.opencv.core.Rect; //導入依賴的package包/類
/**
* Takes the base OpenCV list of contours and changes the output to be easier to
* work with.
*
* @param contours
* The input from the base OpenCV contours output
*/
private void createParticleReports (List<MatOfPoint> contours)
{
ParticleReport[] reports = new ParticleReport[contours.size()];
for (int i = 0; i < reports.length; i++)
{
reports[i] = new ParticleReport();
Rect r = Imgproc.boundingRect(contours.get(i));
reports[i].area = r.area();
reports[i].center = new Point(r.x + (r.width / 2),
r.y + (r.height / 2));
reports[i].boundingRect = r;
}
this.particleReports = reports;
}
示例2: Rectangle
import org.opencv.core.Rect; //導入依賴的package包/類
/**
* Create a rectangle based on a set of points
*
* @param points Set of points (at least 4) defining the rectangle
*/
public Rectangle(Point[] points) {
//Find top-left and bottom-right
Point min = new Point(Double.MAX_VALUE, Double.MAX_VALUE);
Point max = new Point(Double.MIN_VALUE, Double.MIN_VALUE);
for (Point p : points) {
if (p.x < min.x) {
min.x = p.x;
}
if (p.y < min.y) {
min.y = p.y;
}
if (p.x > max.x) {
max.x = p.x;
}
if (p.y > max.y) {
max.y = p.y;
}
}
setRect(new Rect(min, max));
}
示例3: drawRectangles
import org.opencv.core.Rect; //導入依賴的package包/類
/**
* This method is called to overlay rectangles on an image to the video output.
*
* @param image specifies the frame to be rendered to the video output.
* @param detectedObjectRects specifies the detected object rectangles.
* @param color specifies the color of the rectangle outline.
* @param thickness specifies the thickness of the rectangle outline.
*/
public void drawRectangles(Mat image, Rect[] detectedObjectRects, Scalar color, int thickness)
{
//
// Overlay a rectangle on each detected object.
//
synchronized (image)
{
if (detectedObjectRects != null)
{
for (Rect r: detectedObjectRects)
{
//
// Draw a rectangle around the detected object.
//
Imgproc.rectangle(
image, new Point(r.x, r.y), new Point(r.x + r.width, r.y + r.height), color, thickness);
}
}
videoSource.putFrame(image);
}
}
示例4: findAllColors
import org.opencv.core.Rect; //導入依賴的package包/類
public static Point[] findAllColors(ImageWrapper image, int color, int threshold, Rect rect) {
Mat bi = new Mat();
Scalar lowerBound = new Scalar(Color.red(color) - threshold, Color.green(color) - threshold,
Color.blue(color) - threshold, 255);
Scalar upperBound = new Scalar(Color.red(color) + threshold, Color.green(color) + threshold,
Color.blue(color) + threshold, 255);
if (rect != null) {
Core.inRange(new Mat(image.getMat(), rect), lowerBound, upperBound, bi);
} else {
Core.inRange(image.getMat(), lowerBound, upperBound, bi);
}
Mat nonZeroPos = new Mat();
Core.findNonZero(bi, nonZeroPos);
if (nonZeroPos.rows() == 0 || nonZeroPos.cols() == 0) {
return new Point[0];
}
Point[] points = new MatOfPoint(nonZeroPos).toArray();
if (rect != null) {
for (int i = 0; i < points.length; i++) {
points[i].x += rect.x;
points[i].y += rect.y;
}
}
return points;
}
示例5: boundingRect
import org.opencv.core.Rect; //導入依賴的package包/類
public static Rect boundingRect(MatOfPoint points)
{
Mat points_mat = points;
Rect retVal = new Rect(boundingRect_0(points_mat.nativeObj));
return retVal;
}
示例6: CamShift
import org.opencv.core.Rect; //導入依賴的package包/類
public static RotatedRect CamShift(Mat probImage, Rect window, TermCriteria criteria)
{
double[] window_out = new double[4];
RotatedRect retVal = new RotatedRect(CamShift_0(probImage.nativeObj, window.x, window.y, window.width, window.height, window_out, criteria.type, criteria.maxCount, criteria.epsilon));
if(window!=null){ window.x = (int)window_out[0]; window.y = (int)window_out[1]; window.width = (int)window_out[2]; window.height = (int)window_out[3]; }
return retVal;
}
示例7: Mat_to_vector_Rect
import org.opencv.core.Rect; //導入依賴的package包/類
public static void Mat_to_vector_Rect(Mat m, List<Rect> rs) {
if (rs == null)
throw new java.lang.IllegalArgumentException("rs == null");
int count = m.rows();
if (CvType.CV_32SC4 != m.type() || m.cols() != 1)
throw new java.lang.IllegalArgumentException(
"CvType.CV_32SC4 != m.type() || m.rows()!=1\n" + m);
rs.clear();
int[] buff = new int[4 * count];
m.get(0, 0, buff);
for (int i = 0; i < count; i++) {
rs.add(new Rect(buff[4 * i], buff[4 * i + 1], buff[4 * i + 2], buff[4 * i + 3]));
}
}
示例8: stereoRectify
import org.opencv.core.Rect; //導入依賴的package包/類
public static void stereoRectify(Mat cameraMatrix1, Mat distCoeffs1, Mat cameraMatrix2, Mat distCoeffs2, Size imageSize, Mat R, Mat T, Mat R1, Mat R2, Mat P1, Mat P2, Mat Q, int flags, double alpha, Size newImageSize, Rect validPixROI1, Rect validPixROI2)
{
double[] validPixROI1_out = new double[4];
double[] validPixROI2_out = new double[4];
stereoRectify_0(cameraMatrix1.nativeObj, distCoeffs1.nativeObj, cameraMatrix2.nativeObj, distCoeffs2.nativeObj, imageSize.width, imageSize.height, R.nativeObj, T.nativeObj, R1.nativeObj, R2.nativeObj, P1.nativeObj, P2.nativeObj, Q.nativeObj, flags, alpha, newImageSize.width, newImageSize.height, validPixROI1_out, validPixROI2_out);
if(validPixROI1!=null){ validPixROI1.x = (int)validPixROI1_out[0]; validPixROI1.y = (int)validPixROI1_out[1]; validPixROI1.width = (int)validPixROI1_out[2]; validPixROI1.height = (int)validPixROI1_out[3]; }
if(validPixROI2!=null){ validPixROI2.x = (int)validPixROI2_out[0]; validPixROI2.y = (int)validPixROI2_out[1]; validPixROI2.width = (int)validPixROI2_out[2]; validPixROI2.height = (int)validPixROI2_out[3]; }
return;
}
示例9: meanShift
import org.opencv.core.Rect; //導入依賴的package包/類
public static int meanShift(Mat probImage, Rect window, TermCriteria criteria)
{
double[] window_out = new double[4];
int retVal = meanShift_0(probImage.nativeObj, window.x, window.y, window.width, window.height, window_out, criteria.type, criteria.maxCount, criteria.epsilon);
if(window!=null){ window.x = (int)window_out[0]; window.y = (int)window_out[1]; window.width = (int)window_out[2]; window.height = (int)window_out[3]; }
return retVal;
}
示例10: rectify3Collinear
import org.opencv.core.Rect; //導入依賴的package包/類
public static float rectify3Collinear(Mat cameraMatrix1, Mat distCoeffs1, Mat cameraMatrix2, Mat distCoeffs2, Mat cameraMatrix3, Mat distCoeffs3, List<Mat> imgpt1, List<Mat> imgpt3, Size imageSize, Mat R12, Mat T12, Mat R13, Mat T13, Mat R1, Mat R2, Mat R3, Mat P1, Mat P2, Mat P3, Mat Q, double alpha, Size newImgSize, Rect roi1, Rect roi2, int flags)
{
Mat imgpt1_mat = Converters.vector_Mat_to_Mat(imgpt1);
Mat imgpt3_mat = Converters.vector_Mat_to_Mat(imgpt3);
double[] roi1_out = new double[4];
double[] roi2_out = new double[4];
float retVal = rectify3Collinear_0(cameraMatrix1.nativeObj, distCoeffs1.nativeObj, cameraMatrix2.nativeObj, distCoeffs2.nativeObj, cameraMatrix3.nativeObj, distCoeffs3.nativeObj, imgpt1_mat.nativeObj, imgpt3_mat.nativeObj, imageSize.width, imageSize.height, R12.nativeObj, T12.nativeObj, R13.nativeObj, T13.nativeObj, R1.nativeObj, R2.nativeObj, R3.nativeObj, P1.nativeObj, P2.nativeObj, P3.nativeObj, Q.nativeObj, alpha, newImgSize.width, newImgSize.height, roi1_out, roi2_out, flags);
if(roi1!=null){ roi1.x = (int)roi1_out[0]; roi1.y = (int)roi1_out[1]; roi1.width = (int)roi1_out[2]; roi1.height = (int)roi1_out[3]; }
if(roi2!=null){ roi2.x = (int)roi2_out[0]; roi2.y = (int)roi2_out[1]; roi2.width = (int)roi2_out[2]; roi2.height = (int)roi2_out[3]; }
return retVal;
}
示例11: getOptimalNewCameraMatrix
import org.opencv.core.Rect; //導入依賴的package包/類
public static Mat getOptimalNewCameraMatrix(Mat cameraMatrix, Mat distCoeffs, Size imageSize, double alpha, Size newImgSize, Rect validPixROI, boolean centerPrincipalPoint)
{
double[] validPixROI_out = new double[4];
Mat retVal = new Mat(getOptimalNewCameraMatrix_0(cameraMatrix.nativeObj, distCoeffs.nativeObj, imageSize.width, imageSize.height, alpha, newImgSize.width, newImgSize.height, validPixROI_out, centerPrincipalPoint));
if(validPixROI!=null){ validPixROI.x = (int)validPixROI_out[0]; validPixROI.y = (int)validPixROI_out[1]; validPixROI.width = (int)validPixROI_out[2]; validPixROI.height = (int)validPixROI_out[3]; }
return retVal;
}
示例12: onFaceDetected
import org.opencv.core.Rect; //導入依賴的package包/類
@Override
public void onFaceDetected(Rect faceOpenCV, Face face) {
if (!isStopped && view != null) {
view.drawFace(faceOpenCV, matrixRgba);
view.startEyesDetection(faceOpenCV);
}
}
示例13: horizontalScale
import org.opencv.core.Rect; //導入依賴的package包/類
public static Rect horizontalScale(Rect original, double factor) {
double width = original.br().x - original.tl().x;
double newWidth = width * factor;
double newLeft = original.tl().x - ((newWidth - width) / 2);
double height = original.br().y - original.tl().y;
return new Rect((int) newLeft, (int) original.tl().y, (int) newWidth, (int) height);
}
示例14: startThread
import org.opencv.core.Rect; //導入依賴的package包/類
public void startThread() {
if (thread == null) {
// Create a new thread that will constantly evaluate new camera frames
thread = new Thread(() -> {
Mat image = new Mat(CAMERA_HEIGHT, CAMERA_WIDTH, 6);
while (!Thread.interrupted()) {
// Check whether it's time to evaluate a new rame
currentFrameTime = sink.grabFrameNoTimeout(image);
if (currentFrameTime == 0 || currentFrameTime == prevFrameTime) {
continue;
}
prevFrameTime = currentFrameTime;
// Process image using generated pipeline
pipeline.process(image);
// Get pipeline objects
ArrayList<MatOfPoint> mops = pipeline.filterContoursOutput();
// Evaluate objects
for (MatOfPoint mop : mops) {
Rect bRect = Imgproc.boundingRect(mop);
Imgproc.rectangle(image, bRect.tl(), bRect.br(), new Scalar(255, 0, 255));
// TODO: Evaluate objects
}
// Send the evaluated image to the output stream
output.putFrame(image);
}
});
thread.start();
}
}
示例15: floodFill
import org.opencv.core.Rect; //導入依賴的package包/類
public static int floodFill(Mat image, Mat mask, Point seedPoint, Scalar newVal, Rect rect, Scalar loDiff, Scalar upDiff, int flags)
{
double[] rect_out = new double[4];
int retVal = floodFill_0(image.nativeObj, mask.nativeObj, seedPoint.x, seedPoint.y, newVal.val[0], newVal.val[1], newVal.val[2], newVal.val[3], rect_out, loDiff.val[0], loDiff.val[1], loDiff.val[2], loDiff.val[3], upDiff.val[0], upDiff.val[1], upDiff.val[2], upDiff.val[3], flags);
if(rect!=null){ rect.x = (int)rect_out[0]; rect.y = (int)rect_out[1]; rect.width = (int)rect_out[2]; rect.height = (int)rect_out[3]; }
return retVal;
}