나는이 시점에서 그레이 스케일 IplImage
을 취급하고 있기 때문에, 나는 할 수 없었다 검정 또는 흰색 픽셀 수를 계산하지만 주어진 "밝기"임계 값보다 높은 픽셀 수를 계산해야합니다. 난 그냥 덜 비싸지 만 여전히 나에게 충분한 결정을 내리는 데 충분한 정보를 제공하므로 국경 픽셀을 사용했습니다.
IplImage *image;
int sum = 0; // Number of light pixels
int threshold = 135; // Light/Dark intensity threshold
/* Count number of light pixels at border of image. Must convert to unsigned char type to make range 0-255. */
// Check every other pixel of top and bottom
for (int i=0; i<(image->width); i+=2) {
if ((unsigned char)image->imageData[i] >= threshold) { // Check top
sum++;
}
if ((unsigned char)image->imageData[(image->width)*(image->height)
- image->width + i] >= threshold) { // Check bottom
sum++;
}
}
//Check every other pixel of left and right Sides
for (int i=0; i<(image->height); i+=2) {
if ((unsigned char)image->imageData[i*(image->width)] >= threshold) { // Check left
sum++;
}
if ((unsigned char)image->imageData[i*(image->width) + (image->width) - 1] >= threshold) { // Check right
sum++;
}
}
// If more than half of the border pixels are light, use inverse threshold to find dark characters
if (sum > ((image->width/2) + (image->height/2))) {
// Use inverse binary threshold because background is light
}
else {
// Use standard binary threshold because background is dark
}
검은 색 비율의 흰색 픽셀 백분율을 비교하십시오. –
그레이 스케일 이미지를 사용하고 있으므로 순수한 검정색과 순수한 검정색을 비교할 수 없습니다. 아래에 내 솔루션을 게시했습니다. –