Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
53 lines (40 loc) · 1.81 KB

File metadata and controls

53 lines (40 loc) · 1.81 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package me;
import static org.opencv.imgcodecs.Imgcodecs.imread;
import static org.opencv.imgcodecs.Imgcodecs.imwrite;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;
import origami.Origami;
import origami.utils.Downloader;
public class BodyClassifier {
static final String DEFAULT_CLASSIFIER = "https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_upperbody.xml";
static final String DEFAULT_IMAGE = "https://www.netclipart.com/pp/m/106-1066497_suit-man-png-man-in-suit-png.png";
static final String IMAGE_PATH = "image.jpg";
static final String CLASSIFIER_PATH = "haarcascade.xml";
public static void main(String[] args) throws Exception {
Origami.init();
String imageUrl = args.length >= 1 && args[0]!=null ? args[0] : DEFAULT_IMAGE;
String classifierUrl = args.length >= 2 && args[1]!=null ? args[1] : DEFAULT_CLASSIFIER;
Downloader.transfer(imageUrl, IMAGE_PATH);
Downloader.transfer(classifierUrl, CLASSIFIER_PATH);
CascadeClassifier classifier = new CascadeClassifier();
classifier.load(CLASSIFIER_PATH);
Mat mat = imread(IMAGE_PATH);
MatOfRect bodies = new MatOfRect();
classifier.detectMultiScale(mat, bodies);
for (Rect body : bodies.toList()) {
Imgproc.rectangle(mat, new Point(body.x, body.y), new Point(body.x + body.width, body.y + body.height),
new Scalar(0, 100, 0), 3);
}
imwrite("output.jpg", mat);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.