how to draw irregular circles java [closed]
In this App I am drawing the circle of a car wheel, but what I need is to draw the contour, for example when the wheel is deflated I want to draw is the contour (ellipse) and not a circle.
for example: image: link text
now i'm doing the red line, but I want the green one
EL CODIGO ES:
import org.opencv.core.Core; 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.core.Size; import org.opencv.highgui.Highgui; import org.opencv.imgproc.Imgproc; import org.opencv.objdetect.CascadeClassifier;
class DetectarCirculos {
public void run() {
int radio = 0; // radius
Point pnt = null;
Mat fuente = Highgui.imread("imagenes/rueda.jpg", Highgui.CV_LOAD_IMAGE_COLOR); // font
Mat destino = new Mat(fuente.rows(), fuente.cols(), fuente.type()); // target
Imgproc.cvtColor(fuente, destino, Imgproc.COLOR_RGB2GRAY);
Imgproc.GaussianBlur(destino, destino, new Size(3, 3), 0, 0);
Mat circulos = new Mat(); // circles
//(Mat image, Mat circles, int method , dp, minDist, param1, param2, minRadius, maxRadius)
Imgproc.HoughCircles(destino, circulos, Imgproc.CV_HOUGH_GRADIENT, 1, 1, 200, 100, 30, 300);
int radios;
Point pt;
System.out.println("" + circulos.cols());
for (int x = 0; x < circulos.cols(); x++) {
double vCirculo[] = circulos.get(0, x);
if (vCirculo == null) {
break;
}
pt = new Point(Math.round(vCirculo[0]), Math.round(vCirculo[1]));
radios = (int) Math.round(vCirculo[2]);
// encontrar radio mayor - finding greater radius
if (radio < radios) {
radio = radios;
pnt = pt;
}
}
// dibujar circulos encontrados - draw found circles
if (circulos.cols()!=0) {
Core.circle(destino, pnt, radio, new Scalar(255, 255, 255), 3);
Core.circle(destino, pnt, 1, new Scalar(255, 0, 0), 3);
}else{
System.out.println("no se encontraron circulos"); // there's no circles
}
Highgui.imwrite("foundCircles.png", destino);
System.out.println("radio mayor "+radio);
}
}
public class Main {
public static void main(String[] args) {
System.out.println("bienvenido a circulandia");
// Load the native library.
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
new DetectarCirculos().run();
}
}
THANKS!
just a tip: always use plain english for var names and comments in your code. the day will come, when you need help from the internet....