Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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/nuzha/Desktop/Outline.jpg");

cv::glob("C:/Users/nuzha/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

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/nuzha/Desktop/Outline.jpg");

cv::glob("C:/Users/nuzha/Desktop/outline/*.jpg", 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

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