0

i want to save detected lines using a probabilistic hough transform. Using a houghlines2 command there is a parameter called line_storage.line_storage is the place where this function stores its result. This can be either a CvMemoryStorage structure or a matrix with N rows.In Probabilistic hough transform mode, The matrix must be N rows by 1 column, and 4 channeled (CV_32FC4). It stores the two end points of the line segments ( (x,y) twice).

i tried to save this matrix in a xml file.but there is a error that is Unhandled exception at 0x75db9617 in project_test.exe: Microsoft C++ exception: cv::Exception at memory location 0x001bf0a0..The code that i used to save the matrix ,is shown below. can you please explain what did i do wrong. and can anyone tell me how to save this matrix in a xml file.

#include "stdafx.h"
#include"cv.h"
#include"highgui\highgui.hpp"
#include<math.h>
#include"cxcore.h"


int main()
 {
IplImage* source=cvLoadImage("image581.jpg");
CvSize imgsize=cvGetSize(source);

IplImage *detected=cvCreateImage(imgsize,8,1);
IplImage* imgBlue=cvCreateImage(imgsize,8,1);
IplImage* imgRed=cvCreateImage(imgsize,8,1);
IplImage* imgGreen=cvCreateImage(imgsize,8,1);


cvSplit(source,imgBlue,imgGreen,imgRed,NULL);

cvAnd(imgBlue,imgGreen,detected);
cvAnd(detected,imgRed,detected);

cvErode(detected,detected);
cvDilate(detected,detected);

cvThreshold(detected,detected,100,250,CV_THRESH_BINARY_INV);

CvMat* lines=cvCreateMat(50,1,CV_32FC4);
cvHoughLines2(detected,lines,CV_HOUGH_PROBABILISTIC,1,CV_PI/180,100,80,5);

cvNamedWindow("Source");
cvNamedWindow("Red");
cvNamedWindow("Final");

    cvShowImage("Source",source);
    cvShowImage("Red",imgRed);
    cvShowImage("Final",detected);

    cvWaitKey(0);

    cvSave("Result-line.xml",lines);

    cvDestroyWindow("Source");
    cvDestroyWindow("Red");
    cvDestroyWindow("Final");
    cvReleaseMat(&lines);


    return 0;

}

DaBler
  • 2,695
  • 2
  • 26
  • 46
Nim4eng
  • 79
  • 1
  • 7

1 Answers1

1

It is throwing exception at

cvHoughLines2(detected,lines,CV_HOUGH_PROBABILISTIC,1,CV_PI/180,100,80,5);

as "destination matrix datatype is inappropriate". Because you have created matrix for CV_32FC4 instead of CV_32SC4. please refer following link of opencv documentation.

http://opencv.willowgarage.com/documentation/feature_detection.html