I need help with my code?

L

LiverLad

Hi i have a large piece of code and i am trying to improve one part.
The code looks at a scanned image and calculates how many lines are
on the image and will section them off the the page is viewed.
But sometimes the lines are not sectioned i think it has something to
do with the values i have put in for certain variables. Here is the
part of the code which deals with this task: (Sorry there are some
quotes and i don't know why its all in green text)


private static void splitTextArea(boolean leftPage) throws
IOException
{
int left = 0,
right = 0 ;
if (leftPage)
{
left = textEdge ;
right = leftEdge + cropWidth ;
}
else
{
left = leftEdge ;
right = textEdge ;
}
int rowWidth = right - left ;

// int backcolour1 = 253 ;
int backcolour1 = 245,
max_light_lines = 4,
max_dark_lines = 8,
lightLineCounter = 0,
darkLineCounter = 0 ;
boolean inLightZone = true,
inTextZone = false ;
int lastY = topEdge,
descender_space = 3 ;
// PrintWriter pout2 = new PrintWriter(new
FileWriter(outDirectory1 +
// File.separator + "xxx.txt")) ;
noOfRows = 0 ;JAVA
int clearance = 40 ;
for (int i = topEdge + clearance ; i < topEdge + cropHeight -
clearance ; i++)
{
int colour = getRowColour(left, right, i) ;
// pout2.println(i + ", " + colour) ;
if (colour >= backcolour1)
{
lightLineCounter++ ;
darkLineCounter-- ;
}
else
{
darkLineCounter++ ;
lightLineCounter-- ;
}
if (lightLineCounter > max_light_lines)
lightLineCounter = max_light_lines ;
if (lightLineCounter < 0)
lightLineCounter = 0 ;
if (darkLineCounter > max_dark_lines)
darkLineCounter = max_dark_lines ;
if (darkLineCounter < 0)
darkLineCounter = 0 ;

if ((lightLineCounter == max_light_lines) &&
(inTextZone))
{
inLightZone = true ;
inTextZone = false ;
int line = noOfRows + 1 ;
int rowHeight = i + descender_space - lastY ;
// message("(" + left + ", " + lastY +
", " + rowWidth + ", " +
// rowHeight + ")") ;
pout1.println("(" + left + ", " + lastY
+ ", " + rowWidth +
", " + rowHeight + ")") ;
rows[noOfRows] = new IntegerQuad(left, lastY, rowWidth,
rowHeight) ;
noOfRows++ ;
lastY = i + descender_space ;
}
else if ((darkLineCounter == max_dark_lines)
&& (inLightZone))
{
inLightZone = false ;
inTextZone = true ;
}
}
// pout2.close() ;
message("no of lines = " + noOfRows) ;
pout1.println("No of Lines = " + noOfRows) ;
pout1.println() ;
} // end of method splitTextArea

private static void splitGlossArea(boolean leftPage)
{
int left = 0,
right = 0 ;
if (leftPage)
{
left = leftEdge ;
right = textEdge ;
}
else
{
left = textEdge ;
right = leftEdge + cropWidth ;
}
int rowWidth = right - left ;
if (rowWidth == 0)
{
message("WARNING: no gloss area found") ;
noOfGlossRows = 0 ;
return ;
}

// int backcolour1 = 253,
int backcolour1 = 245,
max_light_lines = 20,
max_dark_lines = 10,
lightLineCounter = 0,
darkLineCounter = 0 ;
boolean inLightZone = true,
inTextZone = false ;
int lastY = topEdge,
descender_space = 17,
ascender_space = 20 ;
noOfGlossRows = 0 ;
int clearance = 40 ;
for (int i = topEdge + clearance ; i < topEdge + cropHeight -
clearance ; i++)
{
int colour = getRowColour(left, right, i) ;
if (colour >= backcolour1)
{
lightLineCounter++ ;
darkLineCounter-- ;
}
else
{
darkLineCounter++ ;
lightLineCounter-- ;
}
if (lightLineCounter > max_light_lines)
lightLineCounter = max_light_lines ;
if (lightLineCounter < 0)
lightLineCounter = 0 ;
if (darkLineCounter > max_dark_lines)
darkLineCounter = max_dark_lines ;
if (darkLineCounter < 0)
darkLineCounter = 0 ;

if ((lightLineCounter == max_light_lines) &&
(inTextZone))
{
inLightZone = true ;
inTextZone = false ;
int line = noOfGlossRows + 1 ;
int rowHeight = i + descender_space - lastY ;
// message("(" + left + ", " + lastY +
", " + rowWidth + ", " +
// rowHeight + ")") ;
pout1.println("(" + left + ", " + lastY
+ ", " + rowWidth +
", " + rowHeight + ")") ;
glossRows[noOfGlossRows] = new IntegerQuad(left, lastY,
rowWidth,
rowHeight) ;
noOfGlossRows++ ;
lastY = i + descender_space ;
}
else if ((darkLineCounter == max_dark_lines)
&& (inLightZone))
{
inLightZone = false ;
inTextZone = true ;
// this overrides other values of lastY,
// to eliminate gloss whitespace
lastY = i - max_dark_lines - ascender_space ;
}
}

message("no of glosses = " + noOfGlossRows) ;
pout1.println("No of Glosses = " + noOfGlossRows)
;
pout1.close() ;
} // end of method splitGlossArea
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top