使用 16 位 PGM(C++ 接口)时 OpenCV 列索引会跳过行
有一个奇怪的问题。我编写了几个函数来将 mat 转换为 2D int 数组,反之亦然。我首先编写了 3 通道 8 位版本,工作正常,但 16 位灰度版本似乎跳过了其中一个维度上的索引。
基本上每隔一行都是空白。 (只有每隔一个被写入一次。)我唯一能想到的是它与 16 位表示有关。
以下是代码:
// Convert a Mat image to a standard int array
void matToArrayGS(cv::Mat imgIn, unsigned int **array)
{
int i, j;
for(i=0; i<imgIn.rows; i++)
{
for(j=0; j<imgIn.cols; j++)
array[i][j]=imgIn.at<unsigned int>(i,j);
}
}
// Convert an array into a Greyscale Mat image
void arrayToMatGS(unsigned int **arrayin, cv::Mat imgIn)
{
int i, j;
for(i=0; i<imgIn.rows; i++)
{
for(j=0; j<imgIn.cols; j++)
imgIn.at<unsigned int>(i,j)=arrayin[i][j];
}
}
我不禁认为它与 Mat 中的 16 位表示有关,但我找不到这方面的信息。同样奇怪的是,它在一个维度上运行良好,而在另一个维度上则不然......
有人有想法吗?
提前致谢
Having a strange problem. I wrote a couple of functions to convert from an mat into a 2D int array and vice versa. I first wrote 3 channel 8 bit versions which work fine, but the 16-bit grayscale versions seem to be skipping indices on one of the dimensions.
Basically every second row is blank. (Only every second one is written to.) The only thing I can think is that it has something to do with the 16 bit representation.
The following is the code:
// Convert a Mat image to a standard int array
void matToArrayGS(cv::Mat imgIn, unsigned int **array)
{
int i, j;
for(i=0; i<imgIn.rows; i++)
{
for(j=0; j<imgIn.cols; j++)
array[i][j]=imgIn.at<unsigned int>(i,j);
}
}
// Convert an array into a Greyscale Mat image
void arrayToMatGS(unsigned int **arrayin, cv::Mat imgIn)
{
int i, j;
for(i=0; i<imgIn.rows; i++)
{
for(j=0; j<imgIn.cols; j++)
imgIn.at<unsigned int>(i,j)=arrayin[i][j];
}
}
I can't help thinking it has something to do with the 16 bit representation in Mat but I can't find info on this. It's strange also that it works fine in one dimension and not the other....
Anyone have an idea?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是由“unsigned int”使用引起的。对于 16 位灰度图像,尝试使用“unsigned Short”。
I think this is caused by "unsigned int" usage. Try "unsigned short" for 16 bits grayscale image.