1.功能介紹
(1)使用openCV解析了.jpeg、.jpg、.png格式的圖像文件,輸出了圖像的寬、高、通道數;
(2)創建txt格式文件,保存圖像中各像素點的rgba值。
2.環境介紹
操作系統:window10
開發語言:visual studio 2015 c++
3.功能實現過程
3.1環境設置
(1)打開Vs2015,新建項目OpenCV;
(2)屬性-C/C+±常規 附加包含目錄:D:\softInstall\opencv\build\include 下載的opencv的地址,不知道怎么下載可查看第一章節;
(3)添加庫:將安裝的openCV目錄下opencv_world4110d.lib庫拷貝到項目路徑下并配置。
#pragma comment(lib,“./lib/opencv_world4110d.lib”)
3.2代碼實現`
#include <iostream>
#include <opencv2/opencv.hpp>
#include <fstream>
#pragma comment(lib,"./lib/opencv_world4110d.lib") using namespace std;
using namespace cv;
// 函數:獲取并打印像素信息
void printPixelInfo(const Mat& image, int x, int y)
{if (image.channels() == 1) {// 灰度圖像uchar intensity = image.at<uchar>(y, x);cout << "Grayscale pixel at (" << x << ", " << y << "): " << (int)intensity << endl;}else if (image.channels() == 3) {// 彩色圖像 (BGR格式)Vec3b pixel = image.at<Vec3b>(y, x);cout << "Color pixel at (" << x << ", " << y << "): ";cout << "B=" << (int)pixel[0] << ", ";cout << "G=" << (int)pixel