Implementing Stroke Width Estimation
Hi guys, i found an algorithm which is about "stroke width estimation". I have tried to implement it in opencv. And get stuck in the third step. Please i really need help. The algorithm is :
- For each column, count the number of black pixels and the transitions between black and white i.e the number of runs
- Estimate maxwidth by --> maxwidth = (no. of black pixels / total no. of runs) * 1.5
- Repeat step 1 after discarding those black pixels whose run length is greater than maxwidth
- The estimated width is the count of black pixels divided by the count of runs.
For the first step, my code :
int numOfBlack = 0;
int numOfRun = 0;
for(int i=0;i<thresholdImg.cols;i++){
for(int j=0;j<thresholdImg.rows;j++){
if(thresholdImg.at<uchar>(j,i)==0){
numOfBlack++;
if((j+1)<thresholdImg.rows){
if(thresholdImg.at<uchar>(j+1,i)>0){
numOfRun++;
}
}
}
}
}
For the second step, my code :
double maxWidth = ((numOfBlack*1.0)/(numOfRun*1.0))*1.5;
And for the third step, i don't know how to do it, basically i think like this :
int numOfBlack2 = 0;
int numOfRun2 = 0;
for(int i=0;i<thresholdImg.cols;i++){
int coba = 0;
int cobaRun = 0;
for(int j=0;j<thresholdImg.rows;j++){
if(thresholdImg.at<uchar>(j,i)==0){
coba++;
if((j+1)<thresholdImg.rows){
if(thresholdImg.at<uchar>(j+1,i)>0){
cobaRun++;
}
}
}
}
cout<<cobaRun<<endl;
if((cobaRun*1.0<=maxWidth)){
numOfBlack2+=coba;
numOfRun2+=cobaRun;
}
}
And for the fourth step :
double strokeWitdth = ((numOfBlack2*1.0)/(numOfRun2*1.0));
Actually, i confuse in the third step. Can anyone help me ? because i am completely stuck in the third step. Thanks
add a comment