我正在尝试使用 visual c++ express 2010 将 RGB 图像转换为 HSI 颜色空间并打开 CV 2.3.1 并遇到编译错误问题。请任何人都可以帮我解决这个问题,我需要知道如何使用矩阵来保存 H、S 和 I 的值。提前致谢。我使用的代码是。
#include "stdafx.h"
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <opencv2/opencv.hpp>
using namespace std;
#include "cxcore.h"
#include "cv.h"
#include <highgui.h>
using namespace cv;
const string openCVpath = string(getenv("ProgramFiles"))+"\\OpenCV-2.3.1\\samples\\c\\";
int main (int, char**) {
//call image
Mat img1 = imread(openCVpath+"image1.jpg");
unsigned char *input = (unsigned char*)(img1.data);
// To get pixel values of i-th row and j-th cloumn,
double R,G,B,min,H,S,I;
int i,j;
const double PI= 3.14;
for(int i = 0;i < img1.rows ;i++){
for(int j = 0;j < img1.cols ;j++){
B = input[img1.step * j + i ] ;
G = input[img1.step * j + i + 1];
R = input[img1.step * j + i + 2];
}
// calculate the values of Hue, Saturation and Intensity
min = R;
if (G < min)
min = G;
if (B < min)
min = B;
I = (R+G+B)/3.0;
S = 1 - min/I;
if (S == 0.0)
{
H = 0.0;
}
else
{
H = ((R-G)+(R-B))/2.0;
H = H/sqrt((R-G)*(R-G) + (R-B)*(G-B));
H = acos(H);
if (B > G)
{
H = 2*PI - H;
}
H = H/(2*PI);
}
}
ifstream f("file.txt"); //...in your routine
//};
imshow("Image",img1);
cvWaitKey(0);
return 0;
};