C++ 在C+中实现游程平滑算法的尝试+;
这是我的老问题,但我还没有得到任何帮助 我试图实现从Matlab到C的代码++ 此算法的描述如下: 此线程在Matlab中实现RLSA: MatLabCodeC++ 在C+中实现游程平滑算法的尝试+;,c++,algorithm,matlab,opencv,C++,Algorithm,Matlab,Opencv,这是我的老问题,但我还没有得到任何帮助 我试图实现从Matlab到C的代码++ 此算法的描述如下: 此线程在Matlab中实现RLSA: 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_co
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++
有什么想法吗
< Matlab >另一个指标是从1开始,而C++从0开始。< /强> < /P>
感谢OpenCV按行/列索引,而不是x/y索引,因此请改为:
if (tmpText.at<uchar>(j, i) == 0)
^^^^
if(tmpText.at(j,i)==0)
^^^^
您还需要修复使用
at(row,col)
函数的其余代码。OpenCV按行/列索引,而不是按x/y索引,因此请执行以下操作:
if (tmpText.at<uchar>(j, i) == 0)
^^^^
if(tmpText.at(j,i)==0)
^^^^
您还需要修复使用
at(row,col)
函数的其余代码。谢谢@Roger Rowland我终于实现了这个算法,希望它能帮助那些需要它的人
int hor_thres = 22;
int zero_count = 0;
int one_flag = 0;
for (int i = 0; i<tmpImg.rows; i++){
for (int j = 0; j<tmpImg.cols; j++){
if (tmpImg.at<uchar>(i, j) == 255)
{
if (one_flag == 255)
{
if (zero_count <= hor_thres)
{
tmpImg(cv::Range(i, i + 1), cv::Range(j - zero_count, j)).setTo(cv::Scalar::all(255));
}
else
{
one_flag = 0;
}
zero_count = 0;
}
one_flag = 255;
}
else
{
if (one_flag == 255)
{
zero_count = zero_count + 1;
}
}
}
}
int hor_thres=22;
int zero_count=0;
int one_标志=0;
对于(inti=0;i谢谢@Roger Rowland我终于实现了这个算法,希望它能帮助那些需要它的人
int hor_thres = 22;
int zero_count = 0;
int one_flag = 0;
for (int i = 0; i<tmpImg.rows; i++){
for (int j = 0; j<tmpImg.cols; j++){
if (tmpImg.at<uchar>(i, j) == 255)
{
if (one_flag == 255)
{
if (zero_count <= hor_thres)
{
tmpImg(cv::Range(i, i + 1), cv::Range(j - zero_count, j)).setTo(cv::Scalar::all(255));
}
else
{
one_flag = 0;
}
zero_count = 0;
}
one_flag = 255;
}
else
{
if (one_flag == 255)
{
zero_count = zero_count + 1;
}
}
}
}
int hor_thres=22;
int zero_count=0;
int one_标志=0;
对于(inti=0;i如果您有黑色前景和白色背景,那么希望您会发现我的实现很有用
水平齿RLSA
void horizontalRLSA(Mat &input, Mat &output, int thresh)
{
for (int j = 0; j < input.rows; j++)
{
int count = 0;
int flag = 0;
for (int i = 0; i < input.cols; i++)
{
if (input.at<uchar>(j, i) == 255)
{
flag = 255;
count++;
}
else
{
if (flag == 255 && count <= thresh)
{
output(Rect(i - count, j, count, 1)).setTo(Scalar::all(0));
}
flag = 0;
count = 0;
}
}
}
}
void verticalRLSA(Mat &input, Mat &output, int thresh)
{
for (int i = 0; i < input.cols; i++)
{
int count = 0;
int flag = 0;
for (int j = 0; j < input.rows; j++)
{
if (input.at<uchar>(j, i) == 255)
{
flag = 255;
count++;
}
else
{
if (flag == 255 && count <= thresh)
{
output(Rect(i, j - count, 1, count)).setTo(Scalar::all(0));
}
flag = 0;
count = 0;
}
}
}
}
如果你有黑色的前景和白色的背景,那么希望你会发现我的实现有用
水平齿RLSA
void horizontalRLSA(Mat &input, Mat &output, int thresh)
{
for (int j = 0; j < input.rows; j++)
{
int count = 0;
int flag = 0;
for (int i = 0; i < input.cols; i++)
{
if (input.at<uchar>(j, i) == 255)
{
flag = 255;
count++;
}
else
{
if (flag == 255 && count <= thresh)
{
output(Rect(i - count, j, count, 1)).setTo(Scalar::all(0));
}
flag = 0;
count = 0;
}
}
}
}
void verticalRLSA(Mat &input, Mat &output, int thresh)
{
for (int i = 0; i < input.cols; i++)
{
int count = 0;
int flag = 0;
for (int j = 0; j < input.rows; j++)
{
if (input.at<uchar>(j, i) == 255)
{
flag = 255;
count++;
}
else
{
if (flag == 255 && count <= thresh)
{
output(Rect(i, j - count, 1, count)).setTo(Scalar::all(0));
}
flag = 0;
count = 0;
}
}
}
}
谢谢,我认为也有这样的问题,Matlab <代码> HORIMAGE IMAGE(I,J-ONEORUNCTORCT: J-1)= 0,在C++(代码)>(int COL=J-OnEng-计1,Cale @ SayVTANTA是的,就像我上面所说的。“你需要修正你的代码………………………………”我编辑了问题中的C++代码,我得到了新的错误。谢谢,我想也有这个问题,也就是Matlab <代码> HORIMAGE图像(I,J-ONEORUNCTORCT: J-1)=0;< /C> >在C++ ++代码中实现(int COL= J-ONEORITY COUNT 1;COLL J-1;J++){ TMPTrTeXix.At(i 1,COL)=0;} /Case> @ SayVoTura是的,就像我上面所说的,“您需要修复您的代码的其余部分………………”:Hi @ RoGeRoand,我编辑了C++代码中的问题和新的错误,请看一下谢谢。