Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Detect a face using OpenCV in Java

//Detect a face using OpenCV in Java
/* Put haarcascade_frontalface_alt.xml provided by OpenCV(GitHub link attached) 
in Resource folder for easy access */
				Mat imageMatrix =  Imgcodecs.imread(imagePath);
				MatOfRect facesDetected = new MatOfRect();		
				CascadeClassifier cascadeClassifier = new CascadeClassifier(); 
				int minFaceSize = Math.round(imageMatrix.rows() * 0.1f); 
				cascadeClassifier.load("./src/main/resources/haarcascades/haarcascade_frontalface_alt.xml"); 
				cascadeClassifier.detectMultiScale(imageMatrix, 
				  facesDetected, 
				  1.1, 
				  3, 
				  Objdetect.CASCADE_SCALE_IMAGE, 
				  new Size(minFaceSize, minFaceSize), 
				  new Size() 
				);
				//SAVE image
				Rect[] facesArray = facesDetected.toArray(); 
				for(Rect face : facesArray) { 
				    Imgproc.rectangle(imageMatrix, face.tl(), face.br(), new Scalar(0, 0, 255), 3); 
				}
				Imgcodecs.imwrite(imagePath, imageMatrix);
Comment

PREVIOUS NEXT
Code Example
Java :: Java Constructor invocations 
Java :: boxing and unboxing in java pdf 
Java :: could not initialize defaultkotlinsourcesetkt intelij 
Java :: Android: how to mark my app as debuggable? 
Java :: Java Creating strings using the new keyword 
Java :: javafx stage always on top 
Java :: How can I store user inputs in an array of integers? 
Java :: javafx add vm options 
Java :: text field background color swing 
Java :: how many public classes can be allowed in java 
Java :: speak function in java 
Java :: libgdx load file 
Java :: how to print an array in TImber android 
Java :: Algorithms - Max value 
Java :: java new.JFrame(); 
Java :: how to check if a value is integer or not in java 
Java :: reference to an instance method of an arbitrary object of a particular type 
Java :: shuffle a string in java 
Java :: Read array of characters from space separated values in java 
Java :: set skin minecraft entity player 
Java :: adding Executable Jars to Spring Maven Project 
Java :: java 8 list of objects get only first occurance 
Java :: plantuml java 
Java :: Reverse Order Output for Java Do-While Loop 
Java :: load list of integers from console 
Java :: random number in java between 10 and 20 
Java :: recursive in java 
Java :: spring mvc aop transaction management 
Java :: How can i stub Instant object using powermock 
Java :: venatana emergente con texto java 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =