include "stdafx.h"
include "opencv2/imgproc/imgproc.hpp"
include "opencv2/highgui/highgui.hpp"
include "opencv2/objdetect.hpp"
include "opencv2/video/video.hpp"
include < opencv2\opencv.hpp>
include < stdio.h>
include <iostream>
include <fstream>
include <stdlib.h>
include <stdio.h>
using namespace std; using namespace cv; int main() { cv::Ptr<cv::ml::normalbayesclassifier> classifier = cv::ml::NormalBayesClassifier::create();
ifstream myfile("SKIN\\35\\positive.txt");
// new lines will be skipped unless we stop it from happening:
myfile.unsetf(std::ios_base::skipws);
// count the newlines with an algorithm specialized for counting:
unsigned line_count = std::count(
std::istream_iterator<char>(myfile),
std::istream_iterator<char>(),
'\n');
myfile.open("Training Images\\SKIN\\35\\positive.txt");
char* line=0;
string img_location;
Mat trainData;
Mat labels;
for (int i = 0; i < line_count; i++)
{
myfile >> line;
cout << line << endl;
Mat src = imread(strcat("Training Images/SKIN/35/positive.txt",line), 1);
src = src.reshape(1, src.rows*src.cols);
src.convertTo(src, CV_32FC1);
trainData.push_back(src);
labels.push_back(1);
}
classifier->train(trainData, cv::ml::ROW_SAMPLE,labels);
classifier->save("bayes.xml");
free(line);
cout << "Done" << endl;
return 0;
}
i have stored the name of skin pixel images in positive.txt file which the program reads one by one to train the bayes classifier. But i am getting an error invalid null pointer.