-_-'
#Instalujesz OpenCV (tj. rozpakowujesz to co mozna pobrac u nich na stronie zrodlowej)
#Kopiujesz gdzies *.dll
i *.jar
zeby byly w CP.
#Piszesz kod, na przyklad:
import org.opencv.core.*;
import static org.opencv.highgui.Highgui.*;
import static org.opencv.imgproc.Imgproc.*;
public class Main {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static void main(String[] args) {
if(args.length != 1) {
return;
}
Mat image = imread(args[0], 1);
if(image == null) {
System.out.println("reading error");
return;
}
Mat imageGray = new Mat();
cvtColor(image, imageGray, COLOR_BGR2GRAY);
GaussianBlur(imageGray, imageGray, new Size(9, 9), 2, 2);
Mat circles = new Mat();
HoughCircles(imageGray, circles, CV_HOUGH_GRADIENT, 2, imageGray.rows()/4);
for(int i = 0; i < circles.cols(); i++) {
double buf[] = circles.get(0, i);
if(buf == null) {
continue;
}
Point center = new Point(Math.round(buf[0]), Math.round(buf[1]));
int radius = (int)Math.round(buf[2]);
Core.circle(image, center, radius, new Scalar(0, 0, 255), 3, 8, 0);
}
if(imwrite(args[0], image) == false) {
System.out.println("writing error.");
}
}
}
Efekt:
Z czegos takiego:
Na cos takiego: