Note that there are some explanatory texts on larger screens.

plurals
  1. POVector of pointers problem
    primarykey
    data
    text
    <p>I am having quite a bit of trouble with trying to push_back an object of my custom class to a vector of pointers with my custom class as the type. Please see the code below along with the error received. I am using Eclipse with the CDT plugin and OpenCV on windows xp.</p> <p>I have spent so much time trying to find an answer but to no avail! ps I am a student and pointers etc are not my thing!</p> <pre><code> std:: vector&lt;RoadLine&gt;* LaneChangeDetector::roadLines(IplImage* img_8uc1, IplImage* img_8uc3, IplImage* img_edge, std::vector &lt;RoadLine&gt;* roadVector){ CvMemStorage* storage = cvCreateMemStorage(0); CvSeq* lines = 0; CvMemStorage* roadStorage = cvCreateMemStorage(0); CvSeq* roadLines = 0; // Probabalistic Hough transform returns line segments from edge detected image lines = cvHoughLines2( img_edge, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 50, 200, 200 ); // Sequence roadlines, lines with correct slope are added to this sequence roadLines = cvCreateSeq(0, lines-&gt;header_size, lines-&gt;elem_size, roadStorage); // slope double m = 0.0; // Point of intersection CvPoint poi; for(int i = 0; i &lt; lines-&gt;total; i++ ){ CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i); CvPoint pt1 = line[0]; CvPoint pt2 = line[1]; double x1 = double(pt1.x); double y1 = double(pt1.y); double x2 = double(pt2.x); double y2 = double(pt2.y); if(pt1.x == pt2.x){ m = 1.0; } else{ m = (double(y2 - y1)/(double(x2 - x1))); } if( ((m&gt;0.45) &amp;&amp; (m&lt;0.75)) || ((m&lt;-0.45) &amp;&amp; (m&gt;-0.75)) ){ // If the slope is between measured parameters add to roadLines sequence for further analysis cvSeqPush(roadLines, line); } } // otherRoadLine used for comparison CvPoint* otherRoadLine; for(int a=0; a&lt;roadLines-&gt;total; a++){ CvPoint* roadLine = (CvPoint*)cvGetSeqElem(roadLines,a); CvPoint rl1 = roadLine[0]; CvPoint rl2 = roadLine[1]; int lineCount = 0; if(a&gt;0){ // Test the current line against all the previous lines in the sequence. // If the current line is far enough away from all other lines then draw it for(int b=0; b&lt;a; b++){ otherRoadLine = (CvPoint*)cvGetSeqElem(roadLines,b); if((roadLine-&gt;x &gt; ((otherRoadLine-&gt;x) + 200)) || (roadLine-&gt;x &lt; ((otherRoadLine-&gt;x) - 200)) ){ lineCount++; } } if(lineCount == a){ cvLine(img_final, roadLine[0], roadLine[1], CV_RGB(0,0,255), 3, CV_AA, 0 ); RoadLine myLine = RoadLine(roadLine, 1); roadVector-&gt;push_back(myLine); //ERROR OCCURS HERE cvShowImage("Plate Detection", img_final); cvWaitKey(0); } } else{ cvLine(img_final, roadLine[0], roadLine[1], CV_RGB(0,0,255), 3, CV_AA, 0 ); RoadLine myLine = RoadLine(roadLine, 1); roadVector-&gt;push_back(myLine //ERROR OCCURS HERE cvShowImage("Plate Detection", img_final); cvWaitKey(0); } } if(roadVector-&gt;size() &gt;= 2){ int pos = 0; RoadLine line1 = roadVector-&gt;at(pos); RoadLine line2 = roadVector-&gt;at(pos + 1); CvPoint* A = line1.line; CvPoint p1 = A[0]; CvPoint p2 = A[1]; int A1 = p1.y - p2.y; int B1 = p1.x - p2.x; int C1 = (p1.x*p2.y) - (p1.y*p2.x); CvPoint* B = line2.line; CvPoint p3 = B[0]; CvPoint p4 = B[1]; int A2 = p3.y - p4.y; int B2 = p3.x - p4.x; int C2 = (p3.x*p4.y) - (p3.y*p4.x); int det = A2*B1 - A1*B2; if(det == 0){ printf("Lines are parallel"); } else{ int x = ( C1*(p3.x - p4.x) - (p1.x - p2.x)*C2 )/det; int y = ( C1*(p3.y - p4.y) - (p1.y - p2.y)*C2 )/det; poi.x = x; poi.y = y; horizon = poi.x; cvCircle(img_final, poi, 10, CV_RGB(255, 0, 0), 2, CV_AA, 0); } } cvShowImage("Plate Detection", img_final); cvWaitKey(0); return roadVector; } </code></pre> <p>The custom class RoadLine can be seen here</p> <pre><code> #include &lt;cv.h&gt; class RoadLine{ private: CvPoint* line; int lane; public: RoadLine(CvPoint*, int); }; RoadLine::RoadLine(CvPoint* aLine, int aLane){ line = aLine; lane = aLane; } </code></pre> <p>From debugging i can see that "std::vector &lt;RoadLine>* roadVector" is being intialised correctly.</p> <p>Here is what Eclipse tells me:</p> <pre><code>3 std::vector&lt;RoadLine, std::allocator&lt;RoadLine&gt; &gt;::push_back() F:\MinGW\include\c++\3.4.5\bits\stl_vector.h:560 0x0043e3f9 4 void std::_Construct&lt;RoadLine, RoadLine&gt;() F:\MinGW\include\c++\3.4.5\bits\stl_construct.h:81 0x0044015d </code></pre> <p>And the program jumps to this section of code in stl_construct.h</p> <pre><code> template&lt;typename _T1, typename _T2&gt; inline void _Construct(_T1* __p, const _T2&amp; __value) { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 402. wrong new expression in [some_]allocator::construct ::new(static_cast&lt;void*&gt;(__p)) _T1(__value); //DEBUG THROWS ME TO THIS LINE } </code></pre> <p>Again any help would be greatly appreciated.</p> <p>Cheers</p> <p>Pat</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload