本文整理汇总了Java中org.opencv.imgproc.Imgproc.rectangle方法的典型用法代码示例。如果您正苦于以下问题:Java Imgproc.rectangle方法的具体用法?Java Imgproc.rectangle怎么用?Java Imgproc.rectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opencv.imgproc.Imgproc
的用法示例。
在下文中一共展示了Imgproc.rectangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RectangleSubROI
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat RectangleSubROI(Mat input, Rect rect) {
final Mat maskCopyTo = Mat.zeros(input.size(), CvType.CV_8UC1); // ����copyTo������mask����С��ԭͼ����һ��
// floodFill��mask��width��height�����������ͼ��������������أ��������ᱨ��
final Mat maskFloodFill = Mat.zeros(new Size(input.cols() + 2, input.rows() + 2), CvType.CV_8UC1); // ����floodFill������mask���ߴ��ԭͼ��һЩ
// Imgproc.circle(maskCopyTo, new Point(cc.x, cc.y), radius, Scalar.all(255), 2,
// 8, 0); // ����Բ������
Imgproc.rectangle(maskCopyTo, rect.tl(), rect.br(), Scalar.all(255), 2, 8, 0);
Imgproc.floodFill(maskCopyTo, maskFloodFill,
new Point((rect.tl().x + rect.br().x) / 2, (rect.tl().y + rect.br().y) / 2), Scalar.all(255), null,
Scalar.all(20), Scalar.all(20), 4); // ��ˮ��䷨���Բ���ڲ�
// MatView.imshow(maskFloodFill, "Mask of floodFill"); // ����floodFill������mask
// MatView.imshow(maskCopyTo, "Mask of copyTo"); // ����copyTo������mask
final Mat imgRectROI = new Mat();
input.copyTo(imgRectROI, maskCopyTo); // ��ȡԲ�ε�ROI
// MatView.imshow(imgCircularROI, "Circular ROI"); // ��ʾԲ�ε�ROI
return imgRectROI;
}
示例2: HOGDescriptor
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
void HOGDescriptor() {
Mat grayMat = new Mat();
Mat people = new Mat();
//Converting the image to grayscale
Imgproc.cvtColor(originalMat, grayMat, Imgproc.COLOR_BGR2GRAY);
HOGDescriptor hog = new HOGDescriptor();
hog.setSVMDetector(HOGDescriptor.getDefaultPeopleDetector());
MatOfRect faces = new MatOfRect();
MatOfDouble weights = new MatOfDouble();
hog.detectMultiScale(grayMat, faces, weights);
originalMat.copyTo(people);
//Draw faces on the image
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++)
Imgproc.rectangle(people, facesArray[i].tl(), facesArray[i].br(), new Scalar(100), 3);
//Converting Mat back to Bitmap
Utils.matToBitmap(people, currentBitmap);
imageView.setImageBitmap(currentBitmap);
}
示例3: run
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void run() {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
String base = "C:/Books in Progress/Java for Data Science/Chapter 10/OpenCVExamples/src/resources";
CascadeClassifier faceDetector =
new CascadeClassifier(base + "/lbpcascade_frontalface.xml");
Mat image = Imgcodecs.imread(base + "/images.jpg");
MatOfRect faceVectors = new MatOfRect();
faceDetector.detectMultiScale(image, faceVectors);
out.println(faceVectors.toArray().length + " faces found");
for (Rect rect : faceVectors.toArray()) {
Imgproc.rectangle(image, new Point(rect.x, rect.y),
new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 255, 0));
}
Imgcodecs.imwrite("faceDetection.png", image);
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:21,代码来源:DetectFaceDemo.java
示例4: dobj
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private static Mat dobj(CascadeClassifier objDetector, Mat src) {
final Mat dst = src.clone();
final MatOfRect objDetections = new MatOfRect();
objDetector.detectMultiScale(dst, objDetections);
if (objDetections.toArray().length <= 0) {
return src;
}
for (final Rect rect : objDetections.toArray()) {
Imgproc.rectangle(dst, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 0, 255), 2);
}
return dst;
}
示例5: testFindExternalContours
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Test
public void testFindExternalContours(){
contourFinder = new StandardContourFinder();
Mat image = Mat.zeros(100, 100, CvType.CV_8UC1);
Imgproc.rectangle(image, new Point(10, 10), new Point(20, 20), Scalar.all(255));
List<MatOfPoint> contours = contourFinder.findContours(image);
List<Point> expected = Arrays.asList(new Point(10, 10), new Point(10, 20), new Point(20, 20), new Point(20, 10));
assertEquals(1, contours.size());
List<Point> contour = contours.get(0).toList();
assertEquals(expected.size(), contour.size());
for (Point point : expected) {
assertTrue(contour.contains(point));
}
}
示例6: onCameraFrame
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
//Get image size and draw a rectangle on the image for reference
Mat temp = inputFrame.rgba();
Imgproc.rectangle(temp, new Point(temp.cols()/2 - 200, temp.rows() / 2 - 200), new Point(temp.cols() / 2 + 200, temp.rows() / 2 + 200), new Scalar(255,255,255),1);
Mat digit = temp.submat(temp.rows()/2 - 180, temp.rows() / 2 + 180, temp.cols() / 2 - 180, temp.cols() / 2 + 180).clone();
Core.transpose(digit,digit);
int predict_result = mnist.FindMatch(digit);
Imgproc.putText(temp, Integer.toString(predict_result), new Point(50, 150), FONT_HERSHEY_SIMPLEX, 3.0, new Scalar(0, 0, 255), 5);
return temp;
}
示例7: onCameraFrame
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
rotateFlipImage(ImageControllers.getInstance().getFlipType(),
ImageControllers.getInstance().getMakeTranspose(),
mRgba.getNativeObjAddr());
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
mNativeDetector.setMinFaceSize(mAbsoluteFaceSize);
}
MatOfRect faces = new MatOfRect();
if (mDetectorType == JAVA_DETECTOR) {
if (mJavaDetector != null)
mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
}
else if (mDetectorType == NATIVE_DETECTOR) {
if (mNativeDetector != null)
mNativeDetector.detect(mGray, faces);
Log.v(LOG_TAG, "native detect");
}
else {
Log.e(TAG, "Detection method is not selected!");
}
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++)
Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
return mRgba;
}
示例8: run
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
public void run() {
synchronized (this) {
while (runnable) {
if (webSource.grab()) {
try {
webSource.retrieve(fm);
Graphics g = cameraPane.getGraphics();
faceDetector.detectMultiScale(fm, faceDetections);
for (Rect rect : faceDetections.toArray()) {
Imgproc.rectangle(fm, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
}
Highgui.imencode(".bmp", fm, mem);
Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
BufferedImage buff = (BufferedImage) im;
if (g.drawImage(buff, 0, 0, getWidth(), getHeight(), 0, 0, buff.getWidth(), buff.getHeight(), null)) {
if (runnable == false) {
System.out.println("Paused ..... ");
this.wait();
}
}
} catch (Exception ex) {
ex.toString();
}
}
}
}
}
开发者ID:javaspecial,项目名称:Face-detection-and-recognition-desktop-application,代码行数:31,代码来源:FaceDetectorSecurityCamera.java
示例9: testDetectManyObject
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Test
public void testDetectManyObject() {
String opencvDLL = "G:/java/JavaProjectRelease/classchecks/src/main/webapp/WEB-INF/dll/x64/opencv_java320.dll";
System.load(opencvDLL);
String haarcascade = "haarcascade_frontalface_alt.xml";
CascadeClassifier cascade = new CascadeClassifier(XMLFilePath + haarcascade);
Mat src = Imgcodecs.imread(imageDir + "/split/14.jpg");
MatOfRect objects = new MatOfRect();
int scaledWidth = src.width();
DetectObject.detectManyObject(src, cascade, objects, scaledWidth);
Rect [] rects = objects.toArray();
int i = 0;
for(Rect r : rects) {
/*Imgproc.rectangle(src, new Point(r.x-100 , r.y-100 ),
new Point(r.x + r.width + 80,
r.y + r.height + 80), new Scalar(0, 0, 255), 3);*/
Imgproc.rectangle(src, r.tl(),
r.br(), new Scalar(0, 0, 255), 3);
/*r.width += 120;
r.height += 120;
r.x -= 100;
r.y -= 100;
System.out.println(r);
Mat roi = new Mat(src, r);
Imgcodecs.imwrite("e:/classchecks/2017417/split/"+i+".jpg", roi);
i ++;*/
}
Imgcodecs.imwrite("e:/classchecks/2017417/dectctManyObject.jpg", src);
//Imgcodecs.imwrite("e:/classchecks/dectctManyObject.jpg", src);
}
示例10: detectAndDisplay
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
* Method for face detection and tracking
*
* @param frame
* it looks for faces in this frame
*/
private void detectAndDisplay(Mat frame)
{
MatOfRect faces = new MatOfRect();
Mat grayFrame = new Mat();
// convert the frame in gray scale
Imgproc.cvtColor(frame, grayFrame, Imgproc.COLOR_BGR2GRAY);
// equalize the frame histogram to improve the result
Imgproc.equalizeHist(grayFrame, grayFrame);
// compute minimum face size (20% of the frame height, in our case)
if (this.absoluteFaceSize == 0)
{
int height = grayFrame.rows();
if (Math.round(height * 0.2f) > 0)
{
this.absoluteFaceSize = Math.round(height * 0.2f);
}
}
// detect faces
this.faceCascade.detectMultiScale(grayFrame, faces, 1.1, 2, 0 | Objdetect.CASCADE_SCALE_IMAGE,
new Size(this.absoluteFaceSize, this.absoluteFaceSize), new Size());
// each rectangle in faces is a face: draw them!
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++)
{
Imgproc.rectangle(frame, facesArray[i].tl(), facesArray[i].br(), new Scalar(7, 255, 90), 4);
System.out.println(facesArray[i].tl());
System.out.println(facesArray[i].br());
}
}
示例11: VisionTest
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public VisionTest() {
UsbCamera camera = CameraServer.getInstance().startAutomaticCapture(); // cam0 by default
camera.setResolution(IMG_WIDTH, IMG_HEIGHT);
camera.setBrightness(0);
// camera.setExposureManual(100);
camera.setExposureAuto();
CvSource cs= CameraServer.getInstance().putVideo("name", IMG_WIDTH, IMG_HEIGHT);
visionThread = new VisionThread(camera, new GripPipeline(), pipeline -> {
Mat IMG_MOD = pipeline.hslThresholdOutput();
if (!pipeline.filterContoursOutput().isEmpty()) {
//Rect recCombine = Imgproc.boundingRect(pipeline.filterContoursOutput().get(0));
Rect recCombine = computeBoundingRectangle(pipeline.filterContoursOutput());
if (recCombine == null) {
targetDetected = false;
return;
}
targetDetected = true;
computeCoords(recCombine);
synchronized (imgLock) {
centerX = recCombine.x + (recCombine.width / 2);
}
Imgproc.rectangle(IMG_MOD, new Point(recCombine.x, recCombine.y),new Point(recCombine.x + recCombine.width,recCombine.y + recCombine.height), new Scalar(255, 20, 0), 5);
} else {
targetDetected = false;
}
cs.putFrame(IMG_MOD);
});
visionThread.start();
Relay relay = new Relay(RobotMap.RELAY_CHANNEL, Direction.kForward);
relay.set(Relay.Value.kOn);
//this.processImage();
}
示例12: onCameraFrame
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
// 这里执行人脸检测的逻辑, 根据OpenCV提供的例子实现(face-detection)
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
// 翻转矩阵以适配前后置摄像头
if (isFrontCamera) {
Core.flip(mRgba, mRgba, 1);
Core.flip(mGray, mGray, 1);
} else {
Core.flip(mRgba, mRgba, -1);
Core.flip(mGray, mGray, -1);
}
float mRelativeFaceSize = 0.2f;
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
}
MatOfRect faces = new MatOfRect();
if (classifier != null)
classifier.detectMultiScale(mGray, faces, 1.1, 2, 2,
new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
Rect[] facesArray = faces.toArray();
Scalar faceRectColor = new Scalar(0, 255, 0, 255);
for (Rect faceRect : facesArray)
Imgproc.rectangle(mRgba, faceRect.tl(), faceRect.br(), faceRectColor, 3);
return mRgba;
}
示例13: rectangle
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
*
* @Title: rectangle
* @Description: 以检测的人脸图像区域数组在源图像上画矩形框
* @param mImgSRC
* @param rects
* @return
* Mat
*/
public static Mat rectangle(Mat mImgSRC, Rect ...rects ) {
Mat tmp = new Mat();
mImgSRC.copyTo(tmp);
for(Rect r : rects) {
Imgproc.rectangle(tmp, new Point(r.x, r.y), new Point(r.x + r.width, r.y + r.height), new Scalar(0, 0, 255));
}
return tmp;
}
示例14: updateFrame
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void updateFrame()
{
cap.read(frame);
Imgproc.rectangle(frame, new Point(50, 50), new Point(100, 100), new Scalar(0,0,255), -1);
p.repaint();
}
示例15: drawRectangle
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static void drawRectangle(Mat img, Point topLeft, Point bottomRight, Color color, int thickness) {
Imgproc.rectangle(img, topLeft, bottomRight, color.getScalarRGBA(), thickness);
}