PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 25 → Auto crop scanner
Auto crop scanner
Iniciado por Boller, 15,may. 2023 19:52 - No hay respuesta
Miembro registrado
4.521 mensajes
Publicado el 15,mayo 2023 - 19:52
Well, last week I said I would post here a code to autocrop scanners.

this is my code, which is working. As I said, a little slow, but if we have to do manual cropping, it takes longer :)



AutoCropImage(ImageToCrop is Image, ImageIdentify is Image)



// Function to auto crop an image
// Parameters:
// - ImageToCrop: Image to be cropped
// - ImageIdentify: Image to be transformed to better identify the XY coordinate - to perform the "crop"

// Create a copy of the original image
ImageCopy is Image = ImageIdentify

// Set the dimensions of the image
Img_Width is int = ImageCopy..Width
Img_Height is int = ImageCopy..Height

// Defines the start and end coordinates of the cut
StartX is int = Img_Width
StartY is int = Img_Height
EndX is int = 0
EndY is int = 0

ColorINT is int = 16777216 // decimal value of white color

// Scrolls the entire image, bottom to top, right to left, looking for the first pixel with color
// do it every 2 pixels, because an "object" rarely has only 1 pixel and thus, the processing time reduces by half


FOR x = 0 TO Img_Width-1 STEP 2

FOR y = 0 TO Img_Height-1 STEP 2

PixelColor is string = ImageCopy.PixelColor(x, y)

IF PixelColor > CorINT //> RGB(255, 255, 255) // Checks if the pixel is not white

StartX = Min(StartX, x)
StartY = Min(StartY, y)

EndX = Max(EndX, x)
EndY = Max(EndY, y)

END


END

END

RESULT dCrop(ImageToCrop, StartX, StartY, EndX-StartX+1,EndY-StartY+1)

//——————-

pay attention to one thing:

ColorINT is int = 16777216

It's not completely white,.... it's a very light shade, to try to hide some normal "garbage" from flatbed scanners



bom, na semana passada, eu falei que iria postar aqui um código para fazer autocrop de digitalizações

este é o meu código, que está a funcionar. Como eu disse, um pouco lento, mas se tivermos de fazer crop manual, demora mais :)

AutoCropImage(ImageToCrop is Image, ImageIdentify is Image)

// Função para fazer o auto crop de uma imagem
// Parâmetros:
// - ImageToCrop: Imagem a ser cortada
// - ImageIdentify: Imagem a ser transformada para melhor identificar a coordenada XY - para realização do "crop"

// Cria uma cópia da imagem original
ImageCopy is Image = ImageIdentify

// Define as dimensões da imagem
Img_Width is int = ImageCopy..Width
Img_Height is int = ImageCopy..Height

// Define as coordenadas do início e fim do corte
StartX is int = Img_Width
StartY is int = Img_Height
EndX is int = 0
EndY is int = 0

CorINT is int = 16777216 // valor decimal da cor branca

// Percorre toda a imagem, de baixo para cima, da direita para a esquerda, à procura do primeiro pixel com cor
// faz de 2 em 2 pixels, pois raramente um "objeto" tem somente 1 pixele assim, o tempo de processamento reduz a metade


FOR x = 0 TO Img_Width-1 STEP 2

FOR y = 0 TO Img_Height-1 STEP 2

PixelColor is string = ImageCopy.PixelColor(x, y)

IF PixelColor > CorINT //> RGB(255, 255, 255) // Verifica se o pixel não é branco

StartX = Min(StartX, x)
StartY = Min(StartY, y)

EndX = Max(EndX, x)
EndY = Max(EndY, y)

END


END

END

RESULT dCrop(ImageToCrop, StartX, StartY, EndX-StartX+1,EndY-StartY+1)

//————————-

atenção a uma coisa:

CorINT is int = 16777216

Entao, não é completamente branco,.... é uma tonalidade muito clara, para tentar ocultar alguns "lixos" normais do scanners de mesa


Código fornecido por
Joao Ferreira / Portugal
+351 935 554 853

Nosso muito obrigado pela contribuição

Gratidão sempre!!!

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/