【问题标题】:store monochrome bitmap image pixel value(0,1) in text file in opencv在opencv的文本文件中存储单色位图图像像素值(0,1)
【发布时间】:2017-04-16 19:30:52
【问题描述】:

我正在使用 opencv 读取单色位图图像并将其像素值保存到另一个文本文件中。据我所知,单色位图的值是 0 和 1,而不是介于 0 和 255 之间。当我尝试将值保存在文本文件中时,会存储 0 和 255。如果我将像素值除以 255,那么我得到 0 和 1,但输出是不可接受的,因为它没有形成任何字符(单色位图图像是带有字符的扫描文本文件)。 我认为通道的深度、类型或数量存在问题,但无法解决。请帮忙。提前致谢。

这是我的代码:

#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include "math.h"
#include <fstream>
using namespace cv;

using namespace std;

int main(int argc,char **argv)
{
ofstream fout("monochrome_file.txt");
Mat img=imread("1_mono.bmp",CV_THRESH_BINARY);
uchar val;int x;
 if(img.empty())
{
    cout<<"File Not Opened"<<endl;  
}
for(int i=0;i<img.rows;i++)
{
    for(int j=0;j<img.cols;j++)
    {

        val=img.at<uchar>(i,j);
        x=(int)val;
                    x=x/255;
                    fout<<x;
    }

}

waitKey();
return 0;
}

【问题讨论】:

    标签: c++ opencv bitmap


    【解决方案1】:

    在视觉工作室而不是记事本中打开单色文件.txt。所需的图案将可见。

    【讨论】:

      猜你喜欢
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-23
      相关资源
      最近更新 更多