這是我的老問題,涉及RLSA in C++,但我還沒有得到任何幫助。試圖在C++中實現運行長度平滑算法
我試圖執行從Matlab來C++
該算法的描述的代碼:
http://crblpocr.blogspot.fr/2007/06/run-length-smoothing-algorithm-rlsa.htmlhttp://crblpocr.blogspot.fr/2007/06/determination-of-run-length-smoothing.html
有由該線程在Matlab RLSA實現:
http://mathworks.cn/matlabcentral/newsreader/view_thread/318198
MatLabCode
hor_thresh=20;
zeros_count=0;
one_flag=0;
hor_image=image;
for i=1:m
for j=1:n
if(image(i,j)==1)
if(one_flag==1)
if(zeros_count<=hor_thresh)
hor_image(i,j-zeros_count:j-1)=1;
else
one_flag=0;
end
zeros_count=0;
end
one_flag=1;
else
if(one_flag==1)
zeros_count=zeros_count+1;
end
end
end
end
我試圖用C實現++代碼
int hor_thres = 22;
int one_count = 0;
int zero_flag = 0;
Mat tmpImg = Mat(Img.size(), CV_8UC1, Scalar(0, 0, 0));
for (int j = 0; j<Img.rows; j++){
for (int i = 0; i<Img.cols; j++){
if (Img.at<uchar>(j, i) == 0)
{
if (zero_flag == 1)
{
if (one_count <= hor_thres)
{
tmpText(cv::Range(j - zero_count, j), cv::Range(i, i+1)).setTo(cv::Scalar::all(255));
// I want to do the same thing in Matlab as this image(i,j-one_count:j-1)=0;
}
else
{
zero_flag = 1;
}
one_count = 0;
}
zero_flag = 1;
}
else
{
if (zero_flag == 1)
{
one_count = one_count + 1;
}
}
}
}
這一次沒有錯誤,但預計不會結果..
的問題是我想c寫的方式++代碼相同的事情
Matlab的
tmpImg(i,j-one_count:j-1)=0;
C++
tmpText(cv::Range(j - zero_count, j), cv::Range(i, i+1)).setTo(cv::Scalar::all(255));
Anyidea ???
另一件事是在Matlab從1索引開始而C++從0
謝謝
謝謝,我覺得也有這個以及0123發行Matlab的 'hor_image(I,J-one_count:J-1)= 0;' 當我在C++實現 '爲(INT COL = j的 - one_count - 1; col(i-1,col)= 0; }' –
sayvortana
@sayvortana是的,就像我上面說的*「你需要修復你的代碼的其餘部分......」* ... :-) –
嗨@RogerRowland,我編輯了問題中的C++代碼,我得到的新錯誤請看看謝謝 – sayvortana