Ask Your Question

psoriasis's profile - activity

2016-03-18 15:16:09 -0600 received badge  Enthusiast
2016-03-17 12:00:28 -0600 asked a question opencv 3.1.0 winx64 c++ app fails only from within VS 2013 and 2015 IDEs (works on cmd line)

This is an addendum from yesterday's post before I tried VS 2015 and found the same issue. A console app compiled using VS2013 or VS2015 using opencv 3.1.0 works fine form the command line but fails with memory errors under Visual C++. The program as originally developed under opencv 2.4.10 and had not problem under VS 2013

=== This is true for both release and debug builds. i built it, a x64 console app, under Visual Studio 2013. Using process explorer, I can see that I have the exact same command line (i.e. exact same app and args) and working directory for the exe launched via VS and manually from the command line. I can see it's using the same expected libraries (e.g. opencv_world310d for debug).

The opencv 3.1.0 was directly from the download (I didn't build it)

I'm running under Win10 x64.

Though it runs fine directly for the command line, in VS it blows up in the repeat function: First-chance exception at 0x00007FFFB5CF1F08 in HSV.exe: Microsoft C++ exception: cv::Exception at memory location 0x0000008AC80FB010.

That is not the the first opencv routine the program ran so...I'm baffled.

I copyied the repeat source code (out of copy.cpp) and made a repeata function out of it that I compiled and called with my app and that worked but then it blew up later on another opencv call.

If I hadn't had this running constantly for months under opencv 2.4.10 (Under VS2012)* or if it didn't run fine under both debug and release modes (using 3.1.0) outside VS 2013, I'd just chalk it up to a memory error elsewhere that just happen to finally make itself know but given this context I'm thinking it has something to do with the VS2013 environment but I don't know what to do about it.

I took my errant VS2013 project and just changed it so that it linked (and loaded) the 2.4.10 (debug) libs/dlls and can run without any problems So, it seems that just the fact that the project is linking and load 3.1.0 vs 2.4.10 libs/dlls is enough to make it crash but only in the VS2013 IDE(but the same executable and context run just fine from the command line)

2016-03-16 19:08:44 -0600 asked a question opencv app 3.1.0 fails only under VS2013 but 2.4.10 works

A command line app running under Win10 x64.

Using opencv 2.4.10, the console app works both in and outside of the VS2013 IDE (i.e. from a command line).

However, using opencv 3.1.0, after rebuilding the same code under VS2013 IDE, the same app will fail when executing with VS2013 (but does work from a command line)

The errors are always some sort of memory error and always associated with lots of opencv routines.

Note, I have both 2.4.10 and 3.1.0 dlls paths on the path (w/r t their respective build/x64/vc12/bin dirs). There are no DLLS common to both versions of opencv (so there's no possibility of loading the wrong DLL and I can see that it's all correct in process explorer)

So, the only difference between the opencv 2.4.10 and 3.1.0 for the build is one specifies the 2.4.10 build/x64/vc12/lib files to link against while the 3.1.0 the same dir in the 3.1.0 opencv dir tree and the libs specified are also different as per the libs that exist in the build/xt4/vc12/lib:

opencv_world310d.lib

vs

opencv_core2410d.lib opencv_imgproc2410d.lib opencv_highgui2410d.lib opencv_ml2410d.lib opencv_video2410d.lib opencv_features2d2410d.lib opencv_calib3d2410d.lib opencv_objdetect2410d.lib opencv_contrib2410d.lib opencv_legacy2410d.lib opencv_flann2410d.lib

2016-03-16 17:53:58 -0600 asked a question opencv 3.1.0 winx64 c++ app only works outside Visual Studio 2013

This is true for both release and debug builds. i built it, a x64 console app, under Visual Studio 2013. Using process explorer, I can see that I have the exact same command line (i.e. exact same app and args) and working directory for the exe launched via VS and manually from the command line. I can see it's using the same expected libraries (e.g. opencv_world310d for debug).

The opencv 3.1.0 was directly from the download (I didn't build it)

I'm running under Win10 x64.

Though it runs fine directly for the command line, in VS it blows up in the repeat function: First-chance exception at 0x00007FFFB5CF1F08 in HSV.exe: Microsoft C++ exception: cv::Exception at memory location 0x0000008AC80FB010.

That is not the the first opencv routine the program ran so...I'm baffled.

I copyied the repeat source code (out of copy.cpp) and made a repeata function out of it that I compiled and called with my app and that worked but then it blew up later on another opencv call.

If I hadn't had this running constantly for months under opencv 2.4.10 (Under VS2012)* or if it didn't run fine under both debug and release modes (using 3.1.0) outside VS 2013, I'd just chalk it up to a memory error elsewhere that just happen to finally make itself know but given this context I'm thinking it has something to do with the VS2013 environment but I don't know what to do about it.

  • I took my errant VS2013 project and just changed it so that it linked (and loaded) the 2.4.10 (debug) libs/dlls and can run without any problems

So, it seems that just the fact that the project is linking and load 3.1.0 vs 2.4.10 libs/dlls is enough to make it crash but only in the VS2013 IDE(but the same executable and context run just fine from the command line)

2015-02-01 22:18:21 -0600 commented question copyTo is oddly slow for (at least for planes of 3D Mats)

I replaced the copyTo with a simple C loop (nothing generic)

unsigned char * pSource = Frame.data;
unsigned char * pDst = MovieFrames3DPlane.data;
int SourceStep = 1;
int DstStep = MovieFrames3DPlane.step.p[1];
for(int ip=0; ip < Frame.rows * Frame.cols; ip++) {
    *pDst = *pSource;
    pSource +=SourceStep;
    pDst +=DstStep;
}

and got a time just slightly better than matlab's (which is generic).

After thinking about it, I might do "your way", a vector of 2D Mats, because vent fast copying still means a few percent of my time budget and I'll have to do that twice. Unlike sum, I can't do a median (for each pixels across all planes) totally on the fly but I can constrain it via 256 bin histogram, for each pixel, vs sorting each pixel's vector.

2015-02-01 20:47:39 -0600 commented question copyTo is oddly slow for (at least for planes of 3D Mats)

I have several operations that I wan to perform in the 3rd dimension (e.g. median), but I also want to use the planes as images (i.e. the first 2 dimensions).

I find it bizarre that the concept of a 3d matrix seems to such an anathema to opencv. As a person who uses such all the time, albeit it Matlab, it seems quite unnatural limiting not to have it. Why would software that has multidimensional matrices fall apart after 2D requiring people to pick a pseudo 2d format that is likely fine for one use and bad for another (hence your question)? It is logical that any vector function be available across any dimension of any dimensional matrix. After all, it's just a question of the stride when accessing memory.

Anyway, sorry for the whine/rant. I will look at merge/split. Thanks

2015-02-01 15:13:17 -0600 received badge  Editor (source)
2015-02-01 14:14:41 -0600 asked a question copyTo is oddly slow for (at least for planes of 3D Mats)

I know this isn't really a question though I guess I would like to know why. I think it's important to share and I didn't know where else to post this.

In short, copyTo runs about 7x slower than it should. I know this because I made a simple, code below, equivalent copy in matlab and it was that much faster. It's just a memory copy. This isn't any "fancy" matlab function.

Basic setup: reading a frames from a file and inserting them in a preallocated plane (aka slice) of a 3d matrix. After taking some timings I realized that all the time was being spent in copyTo vs the read. So, then I hacked my code into just a copyTo speed test and then I compared that to the equivalent Matlab test.

This is done on a win7x64. The opencv test was compiled in x64 Release (FYI: 2x faster than Debug)

Note that Matlab's memory is contiguous w/r to its first index whereas openCV it's last so to make the comparison fair, I reversed the order of the indices for my matlab test (non-contiguous memory spacing same for Matlab's first dimension slice and opencv's 3rd dimension slice) . Since the matlab test is so much shorter etc, I will give it first with its times.

1) Matlab test. This ran in about 0.19ms/frame. (i.e. top copy F into A(i,:,:))

F=ones(1,448,48,'uint8');
A = zeros(1000,448,48,'uint8');
tic; 
for i=1:1000 
     A(i,:,:) = F; 
end; 
T=toc  % = 0.19 sec. Given 1000 frames also == ms/frame

2) Opencv equivalent. This takes about 1.4 ms / frame. Note, copyTo doesn't treat 2d marices and the equivalent 3d slices the same so extra variables are needed to provide a the same 3d slice view to both the 2d source and 3d slice target to make copyTo "happy". The views point to the same matrix data, or portion thereof, as their original variables.

int nReadFrames = (int)cap.get(CV_CAP_PROP_FRAME_COUNT);
int nFrameCols = (int)cap.get(CV_CAP_PROP_FRAME_WIDTH); // 448
int nFrameRows = (int)cap.get(CV_CAP_PROP_FRAME_HEIGHT); // 48

int a3DMsizes[3] = {nFrameRows,nFrameCols,nReadFrames};
int aslicesizes[3] = {nFrameRows,nFrameCols,1};
Mat MovieFrames3D = Mat::zeros(3,a3DMsizes,CV_8UC1); // target 3d array
Mat FramePlane; // Generic slice that will hava a 3d slice (plane) view of the 2d matrices 
Range MovieFrames3DRanges[] = {Range::all(),Range::all(),Range(0,1)}; // first slice range; 
Mat MovieFrames3DPlane; // slice of the 3d target array

Mat Frame = Mat::ones(nFrameRows,nFrameCols,CV_8UC1);  // for non read/copyTo spead test.  
FramePlane = Mat::Mat(3,aslicesizes,CV_8UC1,Frame.data); // for non read/copyTo spead test.  

MovieFrames3DPlane = MovieFrames3D(MovieFrames3DRanges);    // slice ,aka plane ,0  
int iFrame;
double t = (double)getTickCount(); 
for(iFrame=0;iFrame < nReadFrames;iFrame++) {
    FramePlane.copyTo(MovieFrames3DPlane);//copying Frame  Frames3D(:,:,0) for test only
}
t = ((double)getTickCount() - t)/((double)nReadFrames * getTickFrequency());     
cout << "Times passed in ms per frame: " << t*1000.0 << endl;

EDIT - since I fist posted this, in order ... (more)