There are images (straight straight line can be in any direction):
It is necessary to calculate from which side this straight line (conventionally) is located and rotate the image so that it is DOWN. I tried to look for the greatest length, when the pixels go one after the other, but it turns out very slowly, since 4 cycles for each need.
for (int X = 0; X < image.height()/2; X++) { for (int Y = 0; Y < image.width(); Y++) { if (QColor(image.pixel(X,Y)).name()=="#ffffff") { int i = Y+1; int max_buffer; while(QColor(image.pixel(X,i)).name()=="#ffffff") { max_buffer++; i++; } if(max_buffer>max_top) { max_top = max_buffer; } } } } This cycle is only for upwards, another 3 for other parties and then to compare which is more, etc. I read that it is possible to implement this method and make it more optimized. UPADETE: The image is already binary (black and white, monochrome)!




