1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
int posX = 0, posY = 0;
int totalHeight = 0;
int totalLines = 0;
int totalTop = 0;
for(int i = 0; i < binImage->width; i++)
{
int lineHeight = 0;
int lineTop = 0;
for(int j = 0; j < binImage->height; j++)
{
CvScalar pixel = cvGet2D(binImage, j, i);
if (pixel.val[0] == 255)
{
if (lineTop == 0) lineTop = j;
lineHeight++;
}
}
if (lineHeight >= 2 * (binImage->height / 3)) // Hauteur au moins égale aux 2/3 de l'image
{
if (posX == 0)
{
posX = i;
posY = lineTop;
}
totalTop += lineTop;
totalHeight += lineHeight;
totalLines++;
}
}
int top = totalTop / totalLines;
int height = totalHeight / totalLines;
CvPoint pt1 = cvPoint(posX, top);
CvPoint pt2 = cvPoint(posX + totalLines, top + height);
cvRectangle(image, pt1, pt2, cvScalar(0, 0, 255)); |
Partager