#include <opencv2/opencv.hpp>
#include<vector>
#include <fstream>

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{
  const char* imagename = "2.jpg";

  //从文件中读入图像
  Mat img = imread(imagename);
  ofstream outfile("rgb.txt");

  //如果读入图像失败
  if (img.empty())
  {
    fprintf(stderr, "Can not load image %s\n", imagename);
    return -1;
  }

  int i, j;
  int cPointR, cPointG, cPointB, cPoint;//currentPoint;
  for (i = 1; i < img.rows; i++)
  {
    for (j = 1; j<img.cols; j++)
    {
      cPointB = img.at<Vec3b>(i, j)[0];
      cPointG = img.at<Vec3b>(i, j)[1];
      cPointR = img.at<Vec3b>(i, j)[2];
      cout << "R:"<<cPointR<<" G:"<<cPointG <<" B:"<<cPointB<< endl;
      outfile << i<<"," << j << "," <<cPointR << "," << cPointG << "," << cPointB << " ";
      if (cPointB>100 & cPointR<100 & cPointG<100)
      {
        img.at<Vec3b>(i, j)[0] = 0; //单通道是uchar,没有[0][1][2]
        img.at<Vec3b>(i, j)[1] = 0;
        img.at<Vec3b>(i, j)[2] = 0;
      }
    }
    outfile << endl;
  }

  //显示图像
  imshow("image", img);

  //此函数等待按键,按键盘任意键就返回
  waitKey();

  return 0;
}

Opencv读取图片像素值并保存为txt文件的更多相关文章

  1. Opencv读取图片像素值

    #include <iostream>#include <opencv2/opencv.hpp> using namespace std;using namespace cv; ...

  2. opencv输出图片像素值

    需求:在控制台输出灰度图像的像素值 代码: #include <stdio.h> #include <iostream> #include <opencv2/core/c ...

  3. 图像特征的提取(gaussian,gabor,frangi,hessian,Morphology...)及将图片保存为txt文件

    # -*- coding: utf-8 -*- #2018-2-19 14:30:30#Author:Fourmi_gsj import cv2 import numpy as np import p ...

  4. 文章要保存为TXT文件,其中的图片要怎么办?Python帮你解决

    前言 用 python 爬取你喜欢的 CSDN 的原创文章,保存为TXT文件,不仅查看不方便,而且还无法保存文章中的代码和图片. 今天教你制作成 PDF 慢慢看.万一作者的突然把号给删了,也会保存备份 ...

  5. Android 读取手机SD卡根目录下某个txt文件的文件内容

    1.先看activity_main.xml文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/and ...

  6. python opencv 读取图片 返回图片某像素点的b,g,r值

    转载:https://blog.csdn.net/weixin_41799483/article/details/80884682 #coding=utf-8   #读取图片 返回图片某像素点的b,g ...

  7. python使用cv2显示图片像素值

    给定一张灰度图,显示这张图片的像素值 def show_image_pixel(img): ''' :param img: 需要输出像素值的图像,要求是灰度图 :return: 无返回值 ''' he ...

  8. [opencv]统计每个像素值的数目

    int histo[256] = { 0 };//直方图统计每个像素值的数目 int width = img.cols, height = img.rows; int num_of_pixels = ...

  9. 如何实现用将富文本编辑器内容保存为txt文件并展示

    1.实现思路 创建一个xx.txt文件,存放于项目路径下 用文件流去读取文件内容并将读取的内容存放到页面的富文本编辑器框内 富文本编辑框内容改变后,保存时用文件流的方式保存到xx.txt文件中 提示: ...

随机推荐

  1. leetcode 645. Set Mismatch——凡是要节约空间的题目 都在输入数据上下功夫 不要担心破坏原始的input

    The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of ...

  2. SQL Server循环插入数据

    --循环执行插入10000条数据declare @ID intdeclare @eigyousyocode nvarchar(16)declare @datet datetimedeclare @pl ...

  3. New Concept English three (49)

    31w/m 51error It is a good thing my aunt Harriet died years ago. If she were alive today she would n ...

  4. Object 的一个问题

    var s1 = 'abc';     s1 instanceof String //false var s2 = new String('abc');     s2 instanceof Strin ...

  5. java web工程启动socket服务

    1.新建web工程 2.自定义类 实现ServletContextListener 接口 在contextInitialized方法中启动socket服务的线程 在contextDestroyed方法 ...

  6. php 中改变字符编码的函数 是 iconv()

    json_enocode()  此函数里边接收的数据必须是utf8格式.要不然会输出null

  7. swing之复杂登陆界面的实现

    package jiemian; import gonggong.message; import gonggong.messageType; import gonggong.user; import ...

  8. mac下完全卸载mysql的方法

    sudo rm /usr/local/mysqlsudo rm -rf /usr/local/mysql*sudo rm -rf /Library/StartupItems/MySQLCOMsudo ...

  9. TreeView的性能问题

    最近在帮同事调试一个类似资源管理器的wpf界面,左边TreeView去遍历大目录时UI卡死,刚开始我以为是在UI线程中调用系统API遍历目录的原因,就改为后台遍历,但是没有效果. 根本原因: Tree ...

  10. Poj 2488 A Knight's Journey(搜索)

    Background The knight is getting bored of seeing the same black and white squares again and again an ...