This is my old question related to RLSA in C++, but I havent got any help yet.
I tried to implement the code from Matlab to C++
The description of this algorithm :
http://crblpocr.blogspot.fr/2007/06/run-length-smoothing-algorithm-rlsa.html http://crblpocr.blogspot.fr/2007/06/determination-of-run-length-smoothing.html
There is RLSA implementation in Matlab by this thread :
http://mathworks.cn/matlabcentral/newsreader/view_thread/318198
Matlab
[m,n]=size(imTmpImg);
hor_thresh=22;
one_count=0;
zero_flag=0;
hor_image=imTmpImg;
for i=1:m
for j=1:n
if(imTmpImg(i,j)==0)
if(zero_flag==1)
if(one_count<=hor_thresh)
hor_image(i,j-one_count:j-1)=0;
else
zero_flag=1;
end
one_count=0;
end
zero_flag=1;
else
if(zero_flag==1)
one_count=one_count+1;
end
end
end
end
In C++
Size size = tmpImg.size();
int hor_thres = 22;
int one_count = 0;
int zero_flag = 0;
Mat tmpImgConnected = Mat(tmpText.size(), CV_8UC1, Scalar(0, 0, 0));
for (int i = 0; i<size.width; i++){
for (int j = 0; j<size.height; i++){
if (tmpText.at<uchar>(i, j) == 0){ //ERROR
if (zero_flag == 1){
if (one_count <= hor_thres){
for (int col = j - one_count - 1; col < j - 1; j++) {
tmpTextConnected.at<uchar>(i - 1, col) = 0;
}
}
else
{
zero_flag = 1;
}
one_count = 0;
}
zero_flag = 1;
}
else
{
if (zero_flag == 1)
{
one_count = one_count + 1;
}
}
}
}
I got this error :
Unhandled exception at 0x000000013F579F98 in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x0000000009D3802C.
It error in this line
if (tmpText.at<uchar>(i, j) == 0){ //ERROR
Anyidea?
Thank