Ask Your Question

Nuz's profile - activity

2020-12-01 15:22:39 -0600 received badge  Student (source)
2020-07-03 11:50:19 -0600 received badge  Popular Question (source)
2020-04-19 08:29:21 -0600 received badge  Notable Question (source)
2019-08-01 23:26:00 -0600 received badge  Notable Question (source)
2019-06-14 03:26:36 -0600 received badge  Popular Question (source)
2018-11-29 03:02:52 -0600 received badge  Popular Question (source)
2017-05-21 13:31:59 -0600 commented question Chain code and xml

@LBerger still the same output xml...is there something wrong in the code i provided? Don't know where is the problem

2017-05-21 12:51:20 -0600 commented question Chain code and xml

@LBerger version 3.0

2017-05-21 06:48:25 -0600 asked a question Chain code and xml

Hello, i am having a problem when saving the xml file.. Only a single row is being showed in the xml..but, i want to retrieve several rows with valid values to represent the images found in the folder. Can someone please help me with this.

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include "opencv2/imgcodecs.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/ml.hpp>
  #include <fstream>
#include<string.h>

using namespace std;
using namespace cv;

vector<String> files;

int main() {


Mat image;
double totalCount = 0;

//Mat image = imread("C:/Users/Desktop/Outline.jpg");

cv::glob("C:/Users/Desktop/outline/*.jpg", files);
for (size_t i = 0; i < files.size(); i++) {
    image = imread(files[i]);


    Canny(image, image, 100, 100 * 2, 3, false);

    CvChain* chain;
    CvMemStorage* storage = 0;
    storage = cvCreateMemStorage();

    cvFindContours(&IplImage(image), storage, (CvSeq**)(&chain), sizeof(*chain), CV_RETR_EXTERNAL, 
CV_CHAIN_CODE);

    int total = chain->total;


    // 1 row, 8 cols, filled with zeros, (float type, because we want to normalize later):
    cv::Mat hist(1, 8, CV_32F, Scalar(0));

    for (; chain != NULL; chain = (CvChain*)chain->h_next)
    {
        CvSeqReader reader;
        int i, total = chain->total;

        cvStartReadSeq((CvSeq*)chain, &reader, 0);

        for (i = 0; i < total; i++)
        {
            char code;
            CV_READ_SEQ_ELEM(code, reader);
            int Fchain = (int)code;

            // increase the counter for the respective bin:
            hist.at<float>(0, Fchain)++;

            totalCount++;
        }
    }


        // print the raw histogram:
        cout << "Histo: " << hist << endl;
        cout << "Total: " << totalCount << endl;

        // normalize it:
        Mat prob = hist / totalCount;
        cout << "Proba: " << prob << endl;

        FileStorage fs("freeman.xml", FileStorage::WRITE);
        fs << "chain" << prob;

}


    waitKey(0);

    return 0;

}

This is the xml file that i got: image description

This is a similar xml that i want as result: image description

2017-05-16 13:25:11 -0600 commented question Is there something missing in the chain code?

@LBerger 2.4.9

2017-05-16 12:07:14 -0600 asked a question Is there something missing in the chain code?

I am not able to read the image and how can i retrieve the xml file and save it? Can someone help..

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <iostream>

using namespace std;
using namespace cv;

int main() {

Mat img = imread("Outline.jpg"); //outline of foot


imshow("Test", img);

vector<vector<Point> > contours;

findContours(img, contours, RETR_EXTERNAL, CV_CHAIN_CODE);
cout << Mat(contours[0]) << endl;

findContours(img, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
cout << "CHAIN_APPROX_SIMPLE" << endl;
cout << Mat(contours[0]) << endl;

CvChain* chain = 0;
CvMemStorage* storage = 0;
storage = cvCreateMemStorage(0);
cvFindContours(&IplImage(img), storage, (CvSeq**)(&chain), sizeof(*chain), CV_RETR_TREE, 
CV_CHAIN_CODE);



for (; chain != NULL; chain = (CvChain*)chain->h_next)
{

    CvSeqReader reader;
    int i, total = chain->total;
    cvStartReadSeq((CvSeq*)chain, &reader, 0);
    cout<<"--------------------chain\n";

    for (i = 0; i<total; i++)
    {
        char code;
        CV_READ_SEQ_ELEM(code, reader);
        cout<<"%d"<<code;
    }
}



waitKey(0);

return 0;
    }
2017-03-11 23:37:57 -0600 asked a question Alignment using COG

Hello..i am using COG to align an image. But, when the image is being translated to the center of gravity, it is showing the old image boundary and the new translated image, which is not a good result.What i want is just the new aligned image without the old image boundary. Can someone help me with this?

Here is the code:

   #include "opencv2\opencv.hpp"
     #include<vector>

      using namespace cv;
      using namespace std;

      void moveContour(vector<Point>& allContours, int x, int y)
      {
for (size_t i = 0; i < allContours.size(); i++)
{
    allContours[i].x += x;
    allContours[i].y += y;
}
  }

      int findBiggestContour(vector<vector<Point> > allContours) {
int indexOfBiggestContour = -1;
int sizeOfBiggestContour = 0;
for (int i = 0; i < allContours.size(); i++) {
    if (allContours[i].size() > sizeOfBiggestContour) {
        sizeOfBiggestContour = allContours[i].size();
        indexOfBiggestContour = i;
    }
}
return indexOfBiggestContour;
    }



        int main()
       {

vector<vector<Point>> allContours;
vector<Vec4i> hierarchy;

Mat img = imread("C:/Users/nuzha/Desktop/Contour16.jpg", IMREAD_GRAYSCALE);

//calculate moments
Moments mu = moments(img, true);

Point COG;//center of gravity

COG = Point(mu.m10 / mu.m00, mu.m01 / mu.m00); //find the COG of ROI

Mat drawing = Mat::zeros(img.size(), CV_8UC1);
Point center(drawing.cols / 2, drawing.rows / 2);

Mat alignedImage = Mat::zeros(img.size(), CV_8UC1); //align the contour

circle(img, COG, 2, Scalar(125, 100, 0), 3, 8);
circle(img, center, 2, Scalar(125, 100, 0), 3, 8);


findContours(img, allContours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
int indexOfContour = findBiggestContour(allContours);

if (indexOfContour > -1)
{
    drawContours(drawing, allContours, indexOfContour, Scalar(255), -1, 8, hierarchy);
    std::vector<Point> ROI;
    ROI = allContours[indexOfContour];
    mu = moments(ROI);

    //Translate the ROI to the COG of the image
    int x;//horizontal
    if (COG.x > center.x)
    {
        x = COG.x - center.x;
        x = -x;
    }
    else
    {
        x = (COG.x - center.x)*-1;
    }

    int y;//vertical

    if (COG.y < center.y)
    {
        y = center.y - COG.y;
    }
    else
    {
        y = center.y - COG.y;
    }

    moveContour(allContours[indexOfContour], x, y);
    drawContours(alignedImage, allContours, indexOfContour, Scalar(255), -1, 8, hierarchy);
}

imshow("Aligned", alignedImage);
imwrite("Aligned.jpg", alignedImage);
waitKey();

return 0;
       }
2017-03-03 04:16:19 -0600 commented question Extracting features

@berak how to extract the hog descriptors of all the sample images and put those descriptors inside different Mat Objects (one for each symbol).

2017-03-01 10:48:22 -0600 asked a question Extracting features

I need to extract features for my training data set. Can someone tell me how should i do it?

2017-02-26 07:33:59 -0600 commented question How to save 1 xml file for 1 movement?

@berak I want to know how to save it as a list of hog feature in a single xml?

2017-02-26 04:17:17 -0600 commented question How to save 1 xml file for 1 movement?

Then, i will use the xml file for to perform SVM classification @berak

2017-02-26 02:51:17 -0600 commented question How to save 1 xml file for 1 movement?

@berak yes, but i wanted to perform the hog feature for each frame first :3 I have extracted all frames from a video playing football consisting of different movements...i need to find xml for each movement...and i have already computed the hog feature of a set of frames representing one movement..

2017-02-26 01:29:54 -0600 asked a question How to save 1 xml file for 1 movement?

I am having difficulty in understanding how to save 1 xml file for a movement.

I have a folder of frames and I have performed the hog feature of each frame and save their corresponding xml files in a folder. Now, how to save the xml files into a single xml file, so as to represent one single movement??

2017-02-24 12:14:35 -0600 commented answer Problem in saving xml files

@berak thank you

2017-02-24 06:24:29 -0600 commented question Problem in saving xml files

I need to take a folder of images and perform hog for each images and save their xml files separately first,then use those xml files to store them in a single Filestorage @berak

2017-02-23 12:03:46 -0600 asked a question Problem in saving xml files

I am having difficulty in saving the xml files. I am using a loop to grab all the images in a folder and then to perform HoG. However, it is not saving any of the xml files. But, when done individually it works. Please help..

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <math.h>
#include "opencv2/highgui/highgui.hpp"
#include <vector>
#include "opencv2/objdetect/objdetect.hpp"
#include <stdio.h>
#include <string.h>
#include <ctype.h>

using namespace cv;
using namespace std;

vector<String> files;

int main(int argc, char** argv)
{

cv::glob("C:/Desktop/Extracted Frames/Front View/Feint and Dribble/2. Shooting Move/*.jpg", files);
for (size_t i = 0; i < files.size(); i++) {
    Mat img = imread(files[i]);

    //Mat img = imread("C:/Proj//Front/7.Canny/Feint and Dribble/2. Shooting Move/Canny7.jpg");

Mat imageData;
//Hog to build feature vector
HOGDescriptor hog;
vector<float> descriptors;
hog.winSize = Size(64, 128);
resize(img, imageData, hog.winSize);//resize image 
hog.compute(img, descriptors);
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
//HOG parameters
hog.cellSize = Size(8, 8);
hog.blockSize = Size(16, 16);
hog.nbins = 9;
//namedWindow("HOG");
imshow("Outline Image", img);


vector<float> features1;
//Mat HogFeat;
//Mat HogFeat = Mat(features1, true).reshape(1, 1);
Mat HogFeat = Mat(descriptors, true).reshape(1, 1);
//normalising data
Mat mean, sigma; //matrices to save mean and standard deviation
                 //store descriptor vector into matrix
meanStdDev(HogFeat, mean, sigma); //get mean and std deviation
HogFeat = (HogFeat - mean) / sigma; //normalization

                                    //store normalisation
Mat meansigma;
hconcat(mean, sigma, meansigma);
cout << "mean " << mean << " sigma " << sigma << endl;
cout << "Saving the normalised HOG matrix....." << endl;
//FileStorage storage("normalisation.xml", FileStorage::WRITE);
//storage << "hogfeature" << HogFeat; // basically - it's a key-value store.
//storage.release(); // nothing will happen, unless you actually flush/close it.

                   //Save image
std::stringstream files(std::stringstream::in | std::stringstream::out);

files << "Normalisation" << i << ".xml";
std::cout << "writing " << files.str().c_str() << " to disk" << std::endl;


imwrite(files.str().c_str(), HogFeat);

}

 waitKey(0);


return 0;
 }
2017-02-22 04:17:23 -0600 commented answer Vector subscript Out of Range Exception

How come for a single image it is working, but when using the loop it is not working for all the images? @berak

2017-02-22 00:53:17 -0600 asked a question Vector subscript Out of Range Exception

I am getting a vector subscript out of range exception, and a breakpoint is triggered at line 53. It is saving only 3 images out of all images being processed. How to solve this problem??

#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include "opencv\cv.h"
#include <vector>

using namespace cv;
using namespace std;

vector<String> files;

int main()
{
int largest_area = 0;
int largest_contour_index = 0;
Rect bounding_rect;



    cv::glob("C:/Proj/Folder/5.Morph/Goal Keeping/1. Low balls/*.jpg", files);
for (size_t i = 0; i < files.size(); i++) {
    Mat src = imread(files[i]);

    Mat thr(src.rows, src.cols, CV_8UC1);
    Mat dst(src.rows, src.cols, CV_8UC1, Scalar::all(0));
    cvtColor(src, thr, CV_BGR2GRAY); //Convert to gray
    threshold(thr, thr, 25, 255, THRESH_BINARY); //Threshold the gray

    vector<vector<Point>> contours; // Vector for storing contour
    vector<Vec4i> hierarchy;

    findContours(thr, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE); // Find the      contours in the image

    for (int j = 0; j< contours.size(); j++) // iterate through each contour. 
    {
        double a = contourArea(contours[j], false);  //  Find the area of contour
        if (a>largest_area) {
            largest_area = a;
            largest_contour_index = j;                //Store the index of largest contour
            bounding_rect = boundingRect(contours[j]); // Find the bounding rectangle for biggest     contour
        }

    }


    Scalar color(255, 255, 255);
    ***LINE 53*** drawContours(dst, contours, largest_contour_index, color, CV_FILLED, 8, hierarchy); // Draw the largest contour using previously stored index.
    rectangle(src, bounding_rect, Scalar(0, 255, 0), 1, 8, 0);
    imshow("src", src);
    imshow("Largest Contour", dst);

    // display result
    std::stringstream files(std::stringstream::in | std::stringstream::out);

    files << "Contour" << i << ".jpg";
    std::cout << "writing " << files.str().c_str() << " to disk" << std::endl;


    imwrite(files.str().c_str(), dst);

}


waitKey(0);
return 0;
    }
2017-02-19 01:24:50 -0600 asked a question How to read a folder of images and save as a single xml file?

I want to read a folder of images in sequence and then save them as a single normalisation.xml file. But, the code below is reading only one image. How to do this?

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <math.h>
#include "opencv2/highgui/highgui.hpp"
#include <vector>
#include "opencv2/objdetect/objdetect.hpp"
#include <stdio.h>
#include <string.h>
#include <ctype.h>

  using namespace cv;
 using namespace std;


  int main(int argc, char** argv)
 {
Mat img = imread("C:/Proj/folder/images/Canny.jpg"); //load outline image
Mat imageData;
//Hog to build feature vector
HOGDescriptor hog;
vector<float> descriptors;
hog.winSize = Size(64, 128);
resize(img, imageData, hog.winSize);//resize image 
hog.compute(img, descriptors);
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
//HOG parameters
hog.cellSize = Size(8, 8);
hog.blockSize = Size(16, 16);
hog.nbins = 9;
//namedWindow("HOG");
imshow("Outline Image", img);


vector<float> features1;
//Mat HogFeat;
//Mat HogFeat = Mat(features1, true).reshape(1, 1);
Mat HogFeat = Mat(descriptors, true).reshape(1, 1);
//normalising data
Mat mean, sigma; //matrices to save mean and standard deviation
                 //store descriptor vector into matrix
meanStdDev(HogFeat, mean, sigma); //get mean and std deviation
HogFeat = (HogFeat - mean) / sigma; //normalization

                                    //store normalisation
Mat meansigma;
hconcat(mean, sigma, meansigma);
cout << "mean " << mean << " sigma " << sigma << endl;
cout << "Saving the normalised HOG matrix....." << endl;
FileStorage storage("normalisation.xml", FileStorage::WRITE);
storage << "hogfeature" << HogFeat; // basically - it's a key-value store.
storage.release(); // nothing will happen, unless you actually flush/close it.
waitKey(0);


return 0;
    }
2017-02-12 10:26:55 -0600 asked a question How to play a video with a fixed fps?

I am extracting frames from video using the following code. However, i want a fixed fps(fps=10) for every videos used to extract frames, but it is not giving me the same number of frames for each video, as they are of different time. How can I play every videos with a fixed fps? please help.. I want to extract frames at 10 fps.

#include "opencv2/opencv.hpp"
#include <time.h>
#include <stdio.h>
#include<string>
#include<ctime>

using namespace cv;
 using namespace std;


     const char* videofilename = "C:/Users/Desktop/Movements/Shooting.mp4";
 VideoCapture cap(videofilename); // open a video file
int main(int argc, char** argv)
 {

if (!cap.isOpened())  // check if succeeded
{
    cout << "file " << videofilename << " not found or could not be opened" << endl;
    return -1;
}

namedWindow("output");

//unsigned long counter = 0;


double fps = cap.set(CV_CAP_PROP_FPS, 10);//set the fps of video

//double fps = cap.get(CV_CAP_PROP_FPS);
//cout << "Frame per seconds : " << fps << endl;
Mat frame;

int counter = 0;
    // read frames until end of video:
    while (cap.read(frame))
    {

        if (counter % 2 == 0) {

            cap >> frame;
        }
        else
        {
            counter++;
            continue;
        }

        // display frame
    imshow("output", frame);



                   // adjust the filename by incrementing a counter
    std::stringstream filename(std::stringstream::in | std::stringstream::out);
    filename << "image" << counter++ << ".jpg";

    std::cout << "writing " << filename.str().c_str() << " to disk" << std::endl;

    // save frame to file: image0.jpg, image1.jpg, and so on...
    imwrite(filename.str().c_str(), frame);

     }
    waitKey(0);

return 0;
     }
2017-02-09 02:31:15 -0600 commented answer How to extract frames at 10 fps?

@bjorn89 I wanted to use : double fps = cap.set(CV_CAP_PROP_FPS, 10) Will it give the same result? But it is not working in the code..i don't know why.

2017-02-08 23:56:22 -0600 asked a question How to extract frames at 10 fps?

I am trying to extract and save frames at 10 fps, but using the following code, it is extracting every frames(25 fps). How can I set the fps to 10 fps so that i can extract and save the frames at 10 fps instead of 25 fps? Can somebody please help..

#include "opencv2/opencv.hpp"
#include <time.h>
#include <stdio.h>
#include<string>
#include<ctime>

using namespace cv;
using namespace std;


 const char* videofilename = "C:/Users/Desktop/Movements/Passing/2.outside of the foot.mp4";
 VideoCapture cap(videofilename); // open a video file
 int main(int argc, char** argv)
  {

if (!cap.isOpened())  // check if succeeded
{
    cout << "file " << videofilename << " not found or could not be opened" << endl;
    return -1;
}

namedWindow("output");

unsigned long counter = 0;


//double fps = cap.set(CV_CAP_PROP_FPS, 10);//set the fps of video

double fps = cap.get(CV_CAP_PROP_FPS);
cout << "Frame per seconds : " << fps << endl;
Mat frame;
// read frames until end of video:
while (cap.read(frame))
{

    // display frame
    imshow("output", frame);
    waitKey(25);   // remove this line if you don't need the live output


                   // adjust the filename by incrementing a counter
    std::stringstream filename(std::stringstream::in | std::stringstream::out);
    filename << "image" << counter++ << ".jpg";

    std::cout << "writing " << filename.str().c_str() << " to disk" << std::endl;

    // save frame to file: image0.jpg, image1.jpg, and so on...
    imwrite(filename.str().c_str(), frame);

}
return 0;
    }
2017-02-07 09:36:16 -0600 commented question Too many frames captured in one second

@Akhilesh thank you

2017-02-07 09:05:36 -0600 commented question Too many frames captured in one second

@Der Luftmensch I am using a video consisting of hand movements..what if i lose some of the images in between and this could disrupt the movement?

2017-02-07 08:15:04 -0600 commented question Too many frames captured in one second

@Der Luftmensch But, by using every nth frame, is it possible that some important frames can be lost?

2017-02-07 06:40:26 -0600 asked a question Too many frames captured in one second

I am extracting frames from a video, but it is extracting every frame, and i am getting too many images within a second. But, I want to reduce the number of frames captured per second, else it will end up eating too much space. Could anyone help me with this, any code available will be of great help

2017-02-05 10:59:31 -0600 commented answer How to represent 1 image using 10 frames?

@LBerger opencv 3.0 Ok..so i should use the one that skip the frames

2017-02-05 10:32:04 -0600 commented answer How to represent 1 image using 10 frames?

@LBerger thank you..is it possible to use IplImage to grab the frames?

2017-02-05 09:22:39 -0600 commented question How to represent 1 image using 10 frames?

@LBerger Actually, i want to extract frames at a rate of say 8 fps..thus, having lesser frames in my database, how could it be done? Can you please help?

2017-02-05 03:05:57 -0600 commented question How to represent 1 image using 10 frames?

I want to know how to use 10 frames to represent 1 image, i don't have an idea how to do it..need help @LBerger

2017-02-05 01:22:40 -0600 asked a question How to represent 1 image using 10 frames?

I have been able to find the fps of a 6 sec video and it gives me 25 fps. However, to keep 150 frames is too heavy. How can I use 10 frames to represent 1 image, thus, giving me only 15 images to store? Any piece of code would be of great help.. Here is my code to find fps:

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

 using namespace cv;
  using namespace std;

  int main(int argc, char* argv[])
     {
VideoCapture cap("C:/Users/Desktop/Movements/Passing/2.outside of the foot.mp4");                                  
if (!cap.isOpened())  // if not success, exit program
{
    cout << "Cannot open the video file" << endl;
    return -1;
}

//cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms

double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video

cout << "Frame per seconds : " << fps << endl;

namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

while (1)
{
    Mat frame;

    bool bSuccess = cap.read(frame); // read a new frame from video

    if (!bSuccess) //if not success, break loop
    {
        cout << "Cannot read the frame from video file" << endl;
        break;
    }

    imshow("MyVideo", frame); //show the frame in "MyVideo" window

    if (waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
    {
        cout << "esc key is pressed by user" << endl;
        break;
    }
}

return 0;

    }