교육 이미지의 픽셀 값을 train_data에 입력하고 응답에서이 픽셀의 클래스에 해당하는 색인을 추가해야합니다 (예 : 클래스 스킨의 경우 1, 비 스킨의 경우 0). var_idx 및 sample_idx는 그대로 둘 수 있으며, 이들은 교육 세트의 일부 설명자 또는 샘플을 마스크 아웃하는 데 사용됩니다. 허위로 만들 수있는 경우에 대비하여 모든 설명자 (모든 교육 이미지의 모든 픽셀)를 한꺼번에 가져 오는 방법에 따라 업데이트를 참/거짓으로 설정하거나 교육 이미지를 점차적으로 처리합니다 (메모리 문제의 경우 더 좋을 수 있음).)이 경우 모델을 업데이트해야합니다.
나 코드 (체크, 내가 강하게 대신 기존 C의 운영자 추천을 OpenCV에 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,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, 0, 0, true);
}
을 당신을 명확히하자