Closed karsten-burger closed 9 years ago
It is similar to https://github.com/Itseez/opencv/issues/5318 Fix for master is here: https://github.com/Itseez/opencv/pull/5320
ok thanks, did not see this. we could add my test-program to the sources.
closed as duplicate
Using OpenCV 2.4.9 I wrote a small test program for the LDA (Linear Discriminant Analysis) and got strange runtime errors,
OpenCV Error: Bad argument (Wrong shapes for given matrices. Was size(src) = (2,1), size(W) = (2,1).) in subspaceProject, file /home/abuild/rpmbuild/BUILD/opencv-2.4.9/modules/contrib/src/lda.cpp, line 187
I noticed that it was dependent on a imshow() call before: if I removed it, the error vanished. I used valgrind and got a warning:
Conditional jump or move depends on uninitialised value(s) at cv::LDA::project(cv::_InputArray const&) (lda.cpp:1108) by main (simple_lda_example.cpp:125)
I then inspected the original source code lda.cpp, and found that a class member _dataAsRow is used uninitialised and transposes the data passed to the algorithm. This member is clearly a remnant of some test. It should be removed completely.
I also found that the same error is contained in OpenCV 3.0.0.
I am not allowed to attach the sample program, not even as txt, so I copy it into this description: I copied the original lda.cpp locally and tested the fix in this way:
Makefile:
LOC= simple_lda_example all: $(LOC) clean: rm $(LOC)
CXXFLAGS += -Wall -g cppcheck: cppcheck --enable=all *.cpp $(LOC): LDLIBS += -lopencv_core -lopencv_contrib -lopencv_highgui $(LOC): lda.o
Test program: simple_lda_example.cpp:
// Linear Discriminant Analysis example // // based on https://github.com/s4kibs4mi/opencv-2/blob/master/lda/src/main.cpp // // See overview http://www.bytefish.de/blog/pca_lda_with_gnu_octave/ // K Burger 2015 tested with Opencv 2.4.9
include "opencv2/opencv.hpp"
include
include
include
include
include
using namespace std; using cv::Mat;
typedef vectorcv::Point Contour;
void drawdots(cv::Mat & annot_image, const Contour& points, const cv::Scalar& color) { const int radius = 5, thick = -1; for (unsigned i=0; i < points.size(); ++i) cv::circle(annot_image, points[i], radius, color, thick); }
static void addToContour(Contour& cont, const Mat& row) { cont.push_back( cv::Point(row.at(0,0)_10, row.at(0,1)_10) );
}
int main(int argc, const char *argv[]) { // Example for a Linear Discriminant Analysis // (example taken from: http://www.bytefish.de/wiki/pca_lda_with_gnu_octave) double d[][2] = { //{2, 0}, // test outlier for fun {2, 3}, {3, 4}, {4, 5}, {5, 6}, {5, 7},
}