# Revision history [back]

### I want to classify a object as positive or negative by using SVM, I wrote the following codes. Is the code is right or any suggestions ?

I have 37 images in my database for each postive and negative for training. I have extracted HOG features of each images and labelled as 'Positive' and 'negative'. its saved into 'Hogfeat' Matrix. Is this code need to be improved or any errors? Now i need to load this features into SVM .(I'm just the learning SVM).I have gone through many links , but its not useful for my codes.Please help me to solve this

int main()

{

HOGDescriptor hog;
vector<Point> locs;

for (size_t i = 1; i <= 37; ++i)
{

ostringstream os;
os << "C:/Users/Sam/Desktop/Images/" << "Content\\" << setw(2) << setfill('0') << i << ".JPG";
cout << os.str();

if (!img.data)
{
break;
}
else
{

// obtain feature vector:
vector<float> featureVector;
hog.compute(img, featureVector, Size(32, 32), Size(0, 0));

//HOG features computed for img are stored in featureVector vector to make it into a matrix

Mat Hogfeat(featureVector.size(), 1, CV_32FC1); //label 1

for (int i = 0; i < featureVector.size(); i++)
{
Hogfeat.at<float>(i, 0) = featureVector.at(i);
}

//HOG features are stored in Hogfeat matrix
cout << Hogfeat;
cout << "Postive Images";
system("PAUSE");
}
}
for (size_t i = 1; i <= 37; ++i)
{

ostringstream os;
os << "C:/Users/Sam/Desktop/Images/" << "No humans\\" << setw(2) << setfill('0') << i << ".JPG";
cout << os.str();

if (!img.data)
{
break;
}
else
{

// obtain feature vector:
vector<float> featureVector;
hog.compute(img, featureVector, Size(32, 32), Size(0, 0));

//HOG features computed for img are stored in featureVector vector to make it into a matrix

Mat Hogfeat(featureVector.size(), -1, CV_32FC1); //label -1

for (int i = 0; i < featureVector.size(); i++)
{
Hogfeat.at<float>(i, 0) = featureVector.at(i);
}

//HOG features are stored in Hogfeat matrix
cout << Hogfeat;
cout << "Negative Images";
}

}

return 0;


}

### I want to classify a object as positive or negative by using SVM, I wrote the following codes. Is the code is right or any suggestions ?

I have 37 images in my database for each postive and negative for training. I have extracted HOG features of each images and labelled as 'Positive' and 'negative'. its saved into 'Hogfeat' Matrix. Is this code need to be improved or any errors? Now i need to load this features into SVM .(I'm just the learning SVM).I have gone through many links , but its not useful for my codes.Please help me to solve this

int main()

{

HOGDescriptor hog;
vector<Point> locs;

for (size_t i = 1; i <= 37; ++i)
{

ostringstream os;
os << "C:/Users/Sam/Desktop/Images/" << "Content\\" << setw(2) << setfill('0') << i << ".JPG";
cout << os.str();

if (!img.data)
{
break;
}
else
{

// obtain feature vector:
vector<float> featureVector;
hog.compute(img, featureVector, Size(32, 32), Size(0, 0));

//HOG features computed for img are stored in featureVector vector to make it into a matrix

Mat Hogfeat(featureVector.size(), 1, CV_32FC1); //label 1

for (int i = 0; i < featureVector.size(); i++)
{
Hogfeat.at<float>(i, 0) = featureVector.at(i);
}

//HOG features are stored in Hogfeat matrix
cout << Hogfeat;
cout << "Postive Images";
system("PAUSE");
}
}
for (size_t i = 1; i <= 37; ++i)
{

ostringstream os;
os << "C:/Users/Sam/Desktop/Images/" << "No humans\\" << setw(2) << setfill('0') << i << ".JPG";
cout << os.str();

if (!img.data)
{
break;
}
else
{

// obtain feature vector:
vector<float> featureVector;
hog.compute(img, featureVector, Size(32, 32), Size(0, 0));

//HOG features computed for img are stored in featureVector vector to make it into a matrix

Mat Hogfeat(featureVector.size(), -1, CV_32FC1); //label -1

for (int i = 0; i < featureVector.size(); i++)
{
Hogfeat.at<float>(i, 0) = featureVector.at(i);
}

//HOG features are stored in Hogfeat matrix
cout << Hogfeat;
cout << "Negative Images";
}

}

return 0;


}

### I want to classify a object as positive or negative by using SVM, I wrote the following codes. Is the code is right or any suggestions ?

I have 37 images in my database for each postive and negative for training. I have extracted HOG features of each images and labelled as 'Positive' and 'negative'. its saved into 'Hogfeat' Matrix. Is this code need to be improved or any errors? Now i need to load this features into SVM .(I'm just the learning SVM).I have gone through many links , but its not useful for my codes.Please help me to solve this

int main()

{

HOGDescriptor hog;
vector<Point> locs;

for (size_t i = 1; i <= 37; ++i)
{

ostringstream os;
os << "C:/Users/Sam/Desktop/Images/" << "Content\\" << setw(2) << setfill('0') << i << ".JPG";
cout << os.str();

if (!img.data)
{
break;
}
else
{

// obtain feature vector:
vector<float> featureVector;
hog.compute(img, featureVector, Size(32, 32), Size(0, 0));

//HOG features computed for img are stored in featureVector vector to make it into a matrix

Mat Hogfeat(featureVector.size(), 1, CV_32FC1); //label 1

for (int i = 0; i < featureVector.size(); i++)
{
Hogfeat.at<float>(i, 0) = featureVector.at(i);
}

//HOG features are stored in Hogfeat matrix
cout << Hogfeat;
cout << "Postive Images";
system("PAUSE");
}
}
for (size_t i = 1; i <= 37; ++i)
{

ostringstream os;
os << "C:/Users/Sam/Desktop/Images/" << "No humans\\" << setw(2) << setfill('0') << i << ".JPG";
cout << os.str();

if (!img.data)
{
break;
}
else
{

// obtain feature vector:
vector<float> featureVector;
hog.compute(img, featureVector, Size(32, 32), Size(0, 0));

//HOG features computed for img are stored in featureVector vector to make it into a matrix

Mat Hogfeat(featureVector.size(), -1, CV_32FC1); //label -1

for (int i = 0; i < featureVector.size(); i++)
{
Hogfeat.at<float>(i, 0) = featureVector.at(i);
}

//HOG features are stored in Hogfeat matrix
cout << Hogfeat;
cout << "Negative Images";
}

}

return 0;


}

### I want to classify a object as positive or negative by using SVM, I wrote the following codes. Is the code is right or any suggestions ?

I have 37 images in my database for each postive and negative for training. I have extracted HOG features of each images and labelled as 'Positive' and 'negative'. its saved into 'Hogfeat' Matrix. Is this code need to be improved or any errors? Now i need to load this features into SVM .(I'm just the learning SVM).I have gone through many links , but its not useful for my codes.Please help me to solve thisthis.

int main()

{

HOGDescriptor hog;
vector<Point> locs;

for (size_t i = 1; i <= 37; ++i)
{

ostringstream os;
os << "C:/Users/Sam/Desktop/Images/" << "Content\\" << setw(2) << setfill('0') << i << ".JPG";
cout << os.str();

if (!img.data)
{
break;
}
else
{

// obtain feature vector:
vector<float> featureVector;
hog.compute(img, featureVector, Size(32, 32), Size(0, 0));

//HOG features computed for img are stored in featureVector vector to make it into a matrix

Mat Hogfeat(featureVector.size(), 1, CV_32FC1); //label 1

for (int i = 0; i < featureVector.size(); i++)
{
Hogfeat.at<float>(i, 0) = featureVector.at(i);
}

//HOG features are stored in Hogfeat matrix
cout << Hogfeat;
cout << "Postive Images";
system("PAUSE");
}
}
for (size_t i = 1; i <= 37; ++i)
{

ostringstream os;
os << "C:/Users/Sam/Desktop/Images/" << "No humans\\" << setw(2) << setfill('0') << i << ".JPG";
cout << os.str();

if (!img.data)
{
break;
}
else
{

// obtain feature vector:
vector<float> featureVector;
hog.compute(img, featureVector, Size(32, 32), Size(0, 0));

//HOG features computed for img are stored in featureVector vector to make it into a matrix

Mat Hogfeat(featureVector.size(), -1, CV_32FC1); //label -1

for (int i = 0; i < featureVector.size(); i++)
{
Hogfeat.at<float>(i, 0) = featureVector.at(i);
}

//HOG features are stored in Hogfeat matrix
cout << Hogfeat;
cout << "Negative Images";
}

}

return 0;


}