本文整理汇总了Java中org.opencv.imgproc.Moments类的典型用法代码示例。如果您正苦于以下问题:Java Moments类的具体用法?Java Moments怎么用?Java Moments使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Moments类属于org.opencv.imgproc包,在下文中一共展示了Moments类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: drawContour
import org.opencv.imgproc.Moments; //导入依赖的package包/类
private void drawContour(MatOfPoint contour, Mat smallFrame, int handIndex) {
Moments p = Imgproc.moments(contour);
int x = (int) (p.get_m10() / p.get_m00());
int y = (int) (p.get_m01() / p.get_m00());
Core.circle(smallFrame, new Point(x, y), 4, colors[handIndex]);
MatOfInt hull = new MatOfInt();
Imgproc.convexHull(contour, hull);
List<MatOfPoint> contorsToDraw = new ArrayList<MatOfPoint>();
contorsToDraw.add(contour);
Imgproc.drawContours(smallFrame, contorsToDraw, 0, colors[handIndex], 1);
}
开发者ID:devgi,项目名称:TamTam,代码行数:13,代码来源:ImgHandlerTresh.java
示例2: massCenterMatOfPoint2f
import org.opencv.imgproc.Moments; //导入依赖的package包/类
private Point massCenterMatOfPoint2f(final MatOfPoint2f map) {
final Moments moments = Imgproc.moments(map);
final Point centroid = new Point();
centroid.x = moments.get_m10() / moments.get_m00();
centroid.y = moments.get_m01() / moments.get_m00();
return centroid;
}
开发者ID:phrack,项目名称:ShootOFF,代码行数:8,代码来源:AutoCalibrationManager.java
示例3: getBeaconConfig
import org.opencv.imgproc.Moments; //导入依赖的package包/类
public static int getBeaconConfig(Image img, VuforiaTrackableDefaultListener beacon, CameraCalibration camCal) {
OpenGLMatrix pose = beacon.getRawPose();
if (pose != null && img != null && img.getPixels() != null) {
Matrix34F rawPose = new Matrix34F();
float[] poseData = Arrays.copyOfRange(pose.transposed().getData(), 0, 12);
rawPose.setData(poseData);
float[][] corners = new float[4][2];
corners[0] = Tool.projectPoint(camCal, rawPose, new Vec3F(-127, 276, 0)).getData(); //upper left of beacon
corners[1] = Tool.projectPoint(camCal, rawPose, new Vec3F(127, 276, 0)).getData(); //upper right of beacon
corners[2] = Tool.projectPoint(camCal, rawPose, new Vec3F(127, -92, 0)).getData(); //lower right of beacon
corners[3] = Tool.projectPoint(camCal, rawPose, new Vec3F(-127, -92, 0)).getData(); //lower left of beacon
//getting camera image...
Bitmap bm = Bitmap.createBitmap(img.getWidth(), img.getHeight(), Bitmap.Config.RGB_565);
bm.copyPixelsFromBuffer(img.getPixels());
//turning the corner pixel coordinates into a proper bounding box
Mat crop = bitmapToMat(bm, CvType.CV_8UC3);
float x = Math.min(Math.min(corners[1][0], corners[3][0]), Math.min(corners[0][0], corners[2][0]));
float y = Math.min(Math.min(corners[1][1], corners[3][1]), Math.min(corners[0][1], corners[2][1]));
float width = Math.max(Math.abs(corners[0][0] - corners[2][0]), Math.abs(corners[1][0] - corners[3][0]));
float height = Math.max(Math.abs(corners[0][1] - corners[2][1]), Math.abs(corners[1][1] - corners[3][1]));
//make sure our bounding box doesn't go outside of the image
//OpenCV doesn't like that...
x = Math.max(x, 0);
y = Math.max(y, 0);
width = (x + width > crop.cols())? crop.cols() - x : width;
height = (y + height > crop.rows())? crop.rows() - y : height;
//cropping bounding box out of camera image
final Mat cropped = new Mat(crop, new Rect((int) x, (int) y, (int) width, (int) height));
//filtering out non-beacon-blue colours in HSV colour space
Imgproc.cvtColor(cropped, cropped, Imgproc.COLOR_RGB2HSV_FULL);
//get filtered mask
//if pixel is within acceptable blue-beacon-colour range, it's changed to white.
//Otherwise, it's turned to black
Mat mask = new Mat();
Core.inRange(cropped, BEACON_BLUE_LOW, BEACON_BLUE_HIGH, mask);
Moments mmnts = Imgproc.moments(mask, true);
//calculating centroid of the resulting binary mask via image moments
Log.i("CentroidX", "" + ((mmnts.get_m10() / mmnts.get_m00())));
Log.i("CentroidY", "" + ((mmnts.get_m01() / mmnts.get_m00())));
//checking if blue either takes up the majority of the image (which means the beacon is all blue)
//or if there's barely any blue in the image (which means the beacon is all red or off)
// if (mmnts.get_m00() / mask.total() > 0.8) {
// return VortexUtils.BEACON_ALL_BLUE;
// } else if (mmnts.get_m00() / mask.total() < 0.1) {
// return VortexUtils.BEACON_NO_BLUE;
// }//elseif
//Note: for some reason, we end up with a image that is rotated 90 degrees
//if centroid is in the bottom half of the image, the blue beacon is on the left
//if the centroid is in the top half, the blue beacon is on the right
if ((mmnts.get_m01() / mmnts.get_m00()) < cropped.rows() / 2) {
return BEACON_RED_BLUE;
} else {
return BEACON_BLUE_RED;
}
}
return NOT_VISIBLE;
}
开发者ID:ykarim,项目名称:FTC2016,代码行数:76,代码来源:BeaconUtils.java
示例4: detect
import org.opencv.imgproc.Moments; //导入依赖的package包/类
/**
* Detect the target in the image.
*
* @param frame The image to detect targetDetection in.
* @return The list of possible targetDetection ordered by confidence from greatest to least.
*/
@Override
public List<Target> detect(Mat frame) {
Mat filtered = filter.filter(frame);
ContourFinder contourFinder = new StandardContourFinder();
List<MatOfPoint> contours = contourFinder.findContours(filtered);
filtered.release();
contours = contourFilter.filterContours(contours);
List<Target> detections = new ArrayList<>();
for (MatOfPoint contour : contours) {
Rect boundary = Imgproc.boundingRect(contour);
double aspectRatio = (boundary.width / (double) boundary.height);
double aspectScore = Scorer.score(aspectRatio, targetSpecs.getWidth() / targetSpecs.getHeight());
double areaRatio = Imgproc.contourArea(contour) / (double) boundary.area();
double areaScore = Scorer.score(areaRatio,
targetSpecs.getArea() / (targetSpecs.getHeight() * targetSpecs.getWidth()));
double confidence = Math.round((aspectScore + areaScore) / 2) / 100.0;
Moments moments = Imgproc.moments(contour);
Point centerOfMass = new Point(moments.m10 / moments.m00, moments.m01 / moments.m00, 0);
Target target = new Target(confidence, boundary.width - 1, boundary.height - 1,
new Point(boundary.x, boundary.y, 0), centerOfMass, frame.size());
detections.add(target);
}
detections.sort((a, b) -> {
if (b.getIsTargetProbability() > a.getIsTargetProbability()) {
return 1;
} else if (a.getIsTargetProbability() > b.getIsTargetProbability()) {
return -1;
}
return 0;
});
return detections;
}
开发者ID:kylecorry31,项目名称:Robot-Vision-API,代码行数:50,代码来源:TargetDetector.java
示例5: findLocations
import org.opencv.imgproc.Moments; //导入依赖的package包/类
private void findLocations(Mat searchMat)
{
_locationValues.clear();
SparseIntArray areas = new SparseIntArray(4);
for(int i = 0; i < NUM_CODES; i++)
{
Mat mask = new Mat();
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
if(i == 2)
{
// combine the two ranges for red
Core.inRange(searchMat, LOWER_RED1, UPPER_RED1, mask);
Mat rmask2 = new Mat();
Core.inRange(searchMat, LOWER_RED2, UPPER_RED2, rmask2);
Core.bitwise_or(mask, rmask2, mask);
}
else
Core.inRange(searchMat, COLOR_BOUNDS[i][0], COLOR_BOUNDS[i][1], mask);
Imgproc.findContours(mask, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
for (int contIdx = 0; contIdx < contours.size(); contIdx++)
{
int area;
if ((area = (int)Imgproc.contourArea(contours.get(contIdx))) > 20)
{
Moments M = Imgproc.moments(contours.get(contIdx));
int cx = (int) (M.get_m10() / M.get_m00());
// if a colour band is split into multiple contours
// we take the largest and consider only its centroid
boolean shouldStoreLocation = true;
for(int locIdx = 0; locIdx < _locationValues.size(); locIdx++)
{
if(Math.abs(_locationValues.keyAt(locIdx) - cx) < 10)
{
if (areas.get(_locationValues.keyAt(locIdx)) > area)
{
shouldStoreLocation = false;
break;
}
else
{
_locationValues.delete(_locationValues.keyAt(locIdx));
areas.delete(_locationValues.keyAt(locIdx));
}
}
}
if(shouldStoreLocation)
{
areas.put(cx, area);
_locationValues.put(cx, i);
}
}
}
}
}
开发者ID:thegouger,项目名称:ResistorScanner,代码行数:61,代码来源:ResistorImageProcessor.java
注:本文中的org.opencv.imgproc.Moments类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论