Basically i have to figure out whether the label on on object is straight. I have an edge image of the object. I would like to calculate the distance between the 2 edges on either side in a single row. My algorithm involves iterating through a row until a white pixel is found. Then calculating the number of black pixels until the next white is found. However when i run the code the answer is always zero.
Code:
for(int i = 0; i < img.cols; i++)
{
int num = nms_result.at<int>(i,100);
//cout <<num<<endl;
if(num > 0) {
stage2 = true;
}
if (stage2 ==true)
counter4++;
{
int num2 = nms_result.at<int>(i,100);
;
if ((num2 < 1) && (counter4 >=1 )) {
counter2++;
}
else counter4 = 0;
}
}
I have tried a lot of things but none seem to work.
Problem number 1: If I'm reading your code right, 'num' and 'num2' are always the same, since they're in the same loop.
Problem number 2: What's the output here? a little hard to tell with your formatting. Consider using some indentations with your nested ifs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.