Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 600

Chain code and xml

$
0
0
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 #include #include #include "opencv2/imgcodecs.hpp" #include #include #include #include using namespace std; using namespace cv; vector 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(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](/upfiles/14953671761948909.png) This is a similar xml that i want as result: ![image description](/upfiles/14953770422652225.png)

Viewing all articles
Browse latest Browse all 600

Trending Articles