Created
April 29, 2020 03:21
-
-
Save yptheangel/604a6f2171ee8748b6a7e3982a49878a to your computer and use it in GitHub Desktop.
Draw Face bounding box and face landmarks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bytedeco.opencv.opencv_core.Mat; | |
import org.bytedeco.opencv.opencv_core.Point; | |
import org.bytedeco.opencv.opencv_core.Scalar; | |
import java.util.ArrayList; | |
import java.util.List; | |
import static org.bytedeco.opencv.global.opencv_highgui.*; | |
import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; | |
import static org.bytedeco.opencv.global.opencv_imgproc.circle; | |
import static org.bytedeco.opencv.global.opencv_imgproc.rectangle; | |
public class Infer { | |
public static void main(String[] args) { | |
// {'box': [31, 138, 34, 43], 'confidence': 0.9999946355819702, | |
// 'keypoints': {'left_eye': (42, 154), 'right_eye': (58, 156), 'nose': (50, 164), 'mouth_left': (41, 171), 'mouth_right': (56, 172)}} | |
String testImagePATH = "C:\\Users\\ChooWilson\\Desktop\\coffindance.jpg"; | |
Mat opencvMat = imread(testImagePATH); | |
int x1 = 31; | |
int y1 = 138; | |
int x2 = 31 + 34; | |
int y2 = 138 + 43; | |
List<Point> faceKeypoints = new ArrayList<>(); | |
faceKeypoints.add(new Point(42, 154)); | |
faceKeypoints.add(new Point(58, 156)); | |
faceKeypoints.add(new Point(50, 164)); | |
faceKeypoints.add(new Point(41, 171)); | |
faceKeypoints.add(new Point(56, 172)); | |
rectangle(opencvMat, new Point(x1, y1), new Point(x2, y2), new Scalar(255, 0, 0, 0)); | |
for (Point keypoint : faceKeypoints) { | |
// circle(UMat img, Point center, int radius, Scalar color, int thickness, int lineType, int shift) | |
// thickness = -1 : fill the circle | |
// change radius : change the boldness of cicle | |
circle(opencvMat, keypoint, 2, new Scalar(255, 0, 0, 0), -1, 0, 0); | |
} | |
imshow("Input Image", opencvMat); | |
// Press "Esc" to close window | |
if (waitKey(0) == 27) { | |
destroyAllWindows(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment