#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 OJ:Unique Paths II(唯一路径II)

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  2. 树莓派(Arduino)仿真软件 —— Fritzing

    Fritzing 官网:Fritzing Fritzing 下载地址:Fritzing Download windows 下降 zip 文件解压后,免安装双击 exe 即可运行:

  3. POJ - 3150 :Cellular Automaton(特殊的矩阵,降维优化)

    A cellular automaton is a collection of cells on a grid of specified shape that evolves through a nu ...

  4. Eclipse中Maven配置操作

    1.修改为自己的maven路径 2.对应的自己的仓库设置

  5. LeetCode Output Contest Matches

    原题链接在这里:https://leetcode.com/problems/output-contest-matches/description/ 题目: During the NBA playoff ...

  6. LeetCode 315. Count of Smaller Numbers After Self

    原题链接在这里:https://leetcode.com/problems/count-of-smaller-numbers-after-self/ 题目: You are given an inte ...

  7. 【转】深入剖析Java中的装箱和拆箱

    深入剖析Java中的装箱和拆箱 自动装箱和拆箱问题是Java中一个老生常谈的问题了,今天我们就来一些看一下装箱和拆箱中的若干问题.本文先讲述装箱和拆箱最基本的东西,再来看一下面试笔试中经常遇到的与装箱 ...

  8. git之cherry-pick

    当想把当前分支提交的代码,也在其他分支提交,那可以用cherry-pick命令. 1 假设在master分支commit的id为:abc12345; 2 切换到其他分支,如develop分支; 3 在 ...

  9. angular : copy vs extend

    While using AngularJS, we come across some situation in which we need to copy one object to another ...

  10. WPF开发中Designer和码农之间的合作

    想要用WPF做出一流的软件界面, 必须要Designer和码农通力合作.理想的情况是平时并行开发,Designer用Expression套件(包括Design和Blend)来设计界面,码农开发Mode ...