修复灰度转黑白算法
This commit is contained in:
parent
8ce837c8ca
commit
5eb5aa60e1
|
@ -971,19 +971,29 @@ namespace hg_imgproc
|
||||||
memset(tableData, reverse ? 0 : 1, 256);
|
memset(tableData, reverse ? 0 : 1, 256);
|
||||||
memset(tableData, reverse ? 1 : 0, threshold);
|
memset(tableData, reverse ? 1 : 0, threshold);
|
||||||
|
|
||||||
cv::Mat dst = cv::Mat::zeros(rows, cols, (int)CV_8UC1);
|
int* index_dst = new int[image.cols];
|
||||||
|
int* index_carry = new int[image.cols];
|
||||||
|
|
||||||
|
for (size_t i = 0; i < image.cols; i++)
|
||||||
|
{
|
||||||
|
index_dst[i] = i / 8;
|
||||||
|
index_carry[i] = 7 - (i % 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
cv::Mat dst = cv::Mat::zeros(rows, cols, CV_8UC1);
|
||||||
uchar* ptr_src, * ptr_dst;
|
uchar* ptr_src, * ptr_dst;
|
||||||
for (size_t y = 0; y < rows; y++)
|
for (size_t y = 0; y < rows; y++)
|
||||||
{
|
{
|
||||||
ptr_dst = dst.ptr<uchar>(y);
|
ptr_dst = dst.ptr<uchar>(y);
|
||||||
ptr_src = const_cast<uchar*>(image.ptr<uchar>(y));
|
ptr_src = const_cast<uchar*>(image.ptr<uchar>(y));
|
||||||
for (size_t x = 0; x < image.cols; x++)
|
for (size_t x = 0; x < image.cols; x++)
|
||||||
ptr_dst[x / 8] += tableData[ptr_src[x]] << (x % 8);
|
ptr_dst[index_dst[x]] += tableData[ptr_src[x]] << index_carry[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete[] index_dst;
|
||||||
|
delete[] index_carry;
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// final
|
// final
|
||||||
public:
|
public:
|
||||||
int final(void)
|
int final(void)
|
||||||
|
@ -1540,9 +1550,9 @@ namespace hg_imgproc
|
||||||
cv::Mat bw = imgproc::convert_8bit_2_1bit(m, threshold, reverse, align);
|
cv::Mat bw = imgproc::convert_8bit_2_1bit(m, threshold, reverse, align);
|
||||||
//std::string ret("");
|
//std::string ret("");
|
||||||
|
|
||||||
dst = bw.ptr();
|
//dst = bw.ptr();
|
||||||
for (int i = 0; i < bw.total(); ++i)
|
//for (int i = 0; i < bw.total(); ++i)
|
||||||
dst[i] = reverse_bit(dst[i]);
|
// dst[i] = reverse_bit(dst[i]);
|
||||||
|
|
||||||
return std::string((char*)bw.ptr(), bw.total());
|
return std::string((char*)bw.ptr(), bw.total());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue