目前,我在不同的光线条件和背景下拍摄了大约20张人物照片(脸部/其他身体部位).我还有20个相应的响应,其中皮肤部分标记为红色,其他所有标记为绿色.
我有理解如何使用该功能的问题
bool CvNormalBayesClassifier::train(const CvMat* _train_data,const CvMat* _response,const Cv*Mat _var_idx = 0,const CvMat* _sample_idx=0,bool update=false);
我应该如何使用当前的两个图片库来准备可以作为_train_data和_responses传入的值?
非常感谢.
让我用代码澄清你(没有检查,并使用OpenCV的C接口,我强烈建议而不是旧的C)
int main(int argc,char **argv) { CvNormalBaseClassifier classifier; for (int i = 0; i < argc; ++i) { cv::Mat image = // read in your training image,say cv::imread(argv[i]); // read your mask image cv::Mat mask = ... cv::Mat response = mask == CV_RGB(255,0); // little trick: you said red pixels in your mask correspond to skin,so pixels in responses are set to 1 if corresponding pixel in mask is red,0 otherwise. cv::Mat responseInt; response.convertTo(responsesInt,CV_32S); // train expects a matrix of integers image = image.reshape(0,image.rows*image.cols); // little trick number 2 convert your width x height,N channel image into a witdth*height row matrix by N columns,as each pixel should be considere as a training sample. responsesInt = responsesInt.reshape(0,image.rows*image.cols); // the same,image and responses have the same number of rows (w*h). classifier.train(image,responsesInt,true);
}