我想使用visual C++ express 2010將RGB圖像轉換爲HSI顏色空間並打開CV 2.3.1,並編譯出錯的問題。請任何人都可以幫助我,我需要知道如何使用矩陣來保存H,S和I的值。 我使用的代碼是。將RGB圖像轉換爲HSI顏色空間
#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;
};
究竟是什麼編譯錯誤,你正在得到什麼? – sietschie
這是編譯錯誤。「未處理的0x771fc41f異常在圖像coversion.exe:Microsoft C++異常:cv ::異常在內存位置0x0037e56c」 – Rose
您可以找出異常發生的位置嗎?例如通過使用調試器?或者通過添加一些printfs? – sietschie