Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Bayes classifier not working.

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.

Bayes classifier not working.

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.

Bayes classifier not working.

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;
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.

Bayes classifier not working.

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.

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.

Bayes classifier not working.

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.

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;}

Bayes classifier not working.

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>

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.

using namespace std; using namespace cv; int main() { cv::Ptr<cv::ml::normalbayesclassifier> classifier = cv::ml::NormalBayesClassifier::create();

ifstream myfile("SKIN\\35\\positive.txt");
myfile("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;
myfile.open("positive.txt");
cout << line_count;
string line;
string img_location;
Mat trainData;
Mat labels;

myfile >> line;

int num = line_count;
for (int i = 0; i < line_count; num; i++)
{

    cout << line << endl;
    Mat src = imread(line, 1);

    if (!src.empty())
    {

        src = src.reshape(1, 1);

        //cvtColor(src, src, CV_32S);
        src.convertTo(src, CV_32FC1);


        trainData.push_back(src);


        labels.push_back(1);

        myfile >> line;
    cout << line }

}

trainData.convertTo(trainData, CV_32FC1);
//cout << labels. << endl;
    Mat src = imread(strcat("Training Images/SKIN/35/positive.txt",line), 1);

    src = src.reshape(1, src.rows*src.cols);

    src.convertTo(src, labels.convertTo(labels, 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;}
0;

}

Bayes classifier not working.

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; image description

int main() { cv::Ptr<cv::ml::normalbayesclassifier> classifier = cv::ml::NormalBayesClassifier::create();

ifstream myfile("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("positive.txt");
cout << line_count;
string line;
string img_location;
Mat trainData;
Mat labels;

myfile >> line;

int num = line_count;
for (int i = 0; i < num; i++)
{

    cout << line << endl;
    Mat src = imread(line, 1);

    if (!src.empty())
    {

        src = src.reshape(1, 1);

        //cvtColor(src, src, CV_32S);
        src.convertTo(src, CV_32FC1);


        trainData.push_back(src);


        labels.push_back(1);

        myfile >> line;
    }

}

trainData.convertTo(trainData, CV_32FC1);
//cout << labels. << endl;
labels.convertTo(labels, CV_32FC1);
classifier->train(trainData, cv::ml::ROW_SAMPLE,labels);
classifier->save("bayes.xml");






cout << "Done" << endl;


return 0;

}