Circle cercleCirconscrit(std::vector<cv::Point> contour) {
/*bool br;
Circle res = Circle(0, Point(-1, -1));
double minRadius = 9999999999;
for (int i = 0; i < contour.size(); i += precision) {
cout << "i=" << i + 1 << "/" << contour.size() << endl;
for (int j = i + 1; j < contour.size(); j += precision) {
for (int k = j + 1; k < contour.size(); k += precision) {
br = false;
Circle c(contour[i], contour[j], contour[k]);
//vérif si tous les points du contour sont dans le cercle
Point P = c.getCenter();
double R = c.getRadius();
if (R < minRadius) {
for (int l = 0; l < contour.size(); l += precision) {
if (distanceP(P, contour[l]) > R)
{
br = true;
break;
}
}
if (!br) {
res = c;
minRadius = R;
}
}
}
}
}*/
Point2f center;
float radius;
minEnclosingCircle(contour, center, radius);
return Circle(radius,center);
}
Circle cercleInscrit(std::vector<cv::Point> contour,Size imgSize) {
Mat dist_map;
double* minVal=new double;
double* maxVal=new double;
Point* minLoc=new Point;
Point* maxLoc=new Point;
//création d'une image binaire avec le contour rempli de blanc
Mat src_map = Mat::zeros(imgSize, CV_8UC1);
//remplissage
vector<vector<Point>> polygones;
polygones.push_back(contour);
fillPoly(src_map, polygones, Scalar(255));
imwrite("src_map.jpg", src_map);
distanceTransform(src_map, dist_map, DIST_L2, DIST_MASK_PRECISE);
minMaxLoc(dist_map, minVal, maxVal, minLoc, maxLoc);
return Circle(*maxVal, *maxLoc);
}
for ijk = 6 to 3n-3
for i=0 to least(ijk,n-2)
for j = i+1 to least(ijk,n-1)
k=ijk-i-j
if k>j and k <= n
// on regarde les 3 segments i,j,k
end if
next j
next i
next ijk
RayonBest=0
for ijk = 6 to 3n-3
for i=0 to least(ijk,n-2)
if RayonMax(i)> RayonBest then
for j = i+1 to least(ijk,n-1)
if RayonMax(j)> RayonBest then
k=ijk-i-j
if k>j and k <= n
if RayonMax(k)> RayonBest then
// on regarde les 3 segments i,j,k
// et si ce cercle est valide et mieux que RayonBest, on mémorise ce cercle.
end if
end if
end if
next j
end if
next i
next ijk
Circle cercleInscrit(std::vector<cv::Point> contour,Size imgSize) {
Mat dist_map;
double* minVal=new double;
double* maxVal=new double;
Point* minLoc=new Point;
Point* maxLoc=new Point;
//création d'une image binaire avec le contour rempli de blanc
Mat mask = Mat::zeros(imgSize, CV_8UC1);
//remplissage
vector<vector<Point>> polygones;
polygones.push_back(contour);
fillPoly(mask, polygones, Scalar(255));
//imwrite("mask.jpg", mask);
distanceTransform(mask, dist_map, DIST_L2, DIST_MASK_PRECISE);
minMaxLoc(dist_map, minVal, maxVal, minLoc, maxLoc);
Circle res= Circle(*maxVal, *maxLoc);
free(maxVal);
free(maxLoc);
free(minVal);
free(minLoc);
return res;
}
type ppoint struct {
xx int
yy int
}
func fdistance(P0 ppoint, P1 ppoint) float64 {
return math.Sqrt(float64((P1.xx-P0.xx)*(P1.xx-P0.xx) + (P1.yy-P0.yy)*(P1.yy-P0.yy)))
}
func fDistanceProjection(P0 ppoint, P1 ppoint, P2 ppoint, rayon float64) bool {
// On recherche la projection de P0 sur la droite P1 P2
// Mais on ne s'intéresse à ce point H que s'il est entre P1 et P2
// Si H est en dehors du segment P1 P2, ou si la distance de P0 à H est bien supérieure à rayon, alors return True.
var H ppoint
var k float64
deltaX := float64(P2.xx - P1.xx)
deltaY := float64(P2.yy - P1.yy)
if deltaX == 0 && deltaY == 0 {
// Les points P1 et P2 sont superposés.
return true
}
k = (float64(P0.xx-P1.xx)*deltaX + float64(P0.yy-P1.yy)*deltaY) / (deltaX*deltaX + deltaY*deltaY)
if k < 0 || k > 1 {
// H n'est pas entre P1 et P2, donc ok.
return true
}
H.xx = P1.xx + int(k*float64(P2.xx-P1.xx))
H.yy = P1.yy + int(k*float64(P2.yy-P1.yy))
fmt.Println(" Point H", H.xx, H.yy)
if fdistance(P0, H) < rayon {
return false
}
return true
}
func okCercle(rayon int, CCentre ppoint, P2 ppoint, P3 ppoint) bool {
// Vérifie si le segment P1 P2 est bien tout entier à l'extérieur du cercle de centre CCentre et rde rayon rayon
if fdistance(CCentre, P2) < float64(rayon) {
//fmt.Println(" Point 1 dans le cercle ", rayon)
return false
}
if fdistance(CCentre, P3) < float64(rayon) {
//fmt.Println(" Point 2 dans le cercle ", rayon)
return false
}
if fDistanceProjection(CCentre, P2, P3, float64(rayon)) == false {
//fmt.Println(" Proj dans le cercle ", rayon)
return false
}
return true
}
func main() {
var P1, P2, P3 ppoint
P1.xx = 0
P1.yy = 0
P2.xx = 800
P2.yy = 100
P3.xx = 600
P3.yy = 630
for i := 700; i < 900; i++ {
ok := okCercle(i, P1, P2, P3)
if ok {
fmt.Println(i)
}
}
}
Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 10 invités
Tu pars déja ?
Identification
Pas encore inscrit ?
Ou identifiez-vous :