Ask Your Question
5

Missing Mat::zeros(int ndims, const int* sz, int type)

asked 2013-02-26 23:58:51 -0600

artanis gravatar image

updated 2013-03-07 00:21:23 -0600

Hi everyone,

Sorry to disturb you.

When I try to use the Mat::zeros(int ndims, const int* sz, int type) method, the linker complains "unresolved reference to Mat::zeros(int ndims, const int* sz, int type)". Therefore I try to find the code related to this method, but I cannot find it in the opencv/module/core directory. Could anyone point out the true location of this method ?

PS. It is very strange that I can find zeros(int rows, int cols, int type) and zeros(Size size, int type), but I can't find zeros(int ndims, const int* sz, int type) in the same location.

Thank you. Artanis

UPDATE 1
I have checked opencv's code and I think it really lacks the implement of "zeros(int ndims, const int* sz, int type)". I am rather sure because if we implement this method, we need to use the MatOp_Initializer::assign() function, but this function doesn't support N(N > 2) dimensional Mat.

UPDATE 2
I will try to make a pull request to solve this problem. Hope it works. BTW, if you find the implement of "zeros(int ndims, const int* sz, int type)" in current OpenCV, please let me know. Thank you.

UPDATE 3
The pull request has been merged.

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2013-02-27 07:52:31 -0600

zeros(int ndims, const int* sz, int type) is the old api, referred to as the C-api to create the zeros array.

zeros(Size size, int type) is the new api preferred since openCV2.0, referring to the C++ implementation where pointers are not the way to go anymore :) It's made easier for you so I suggest using the C++ interface, since this is the direction new developments are going also.

edit flag offensive delete link more

Comments

1

And in addition to that, make sure that you have not included the c++ api, by including the cv2 folder, if you still want to go with the c style api.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-02-27 07:53:42 -0600 )edit

Sorry, but your post isn't correct: C++ has the following function: static MatExpr Mat::zeros(int ndims, const int* sz, int type) in core.hpp line 1768 of OpenCV version 2.4.3

Guanta gravatar imageGuanta ( 2013-02-27 08:18:57 -0600 )edit

Indeed, the first versions of the C++ implementations still supported some pointer version. However, it is marked with a yellow line, according to my experience between versions this shows the call is depricated and will be replaced by the two calls above.

This means 2.4.4 will still support the function, but 2.5 will probably not.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-02-27 08:24:15 -0600 )edit

And to be completely correct, the original C versions weren't even completely C but also had some C++ commands :) Its just an evolution from old to newer software as i see it.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-02-27 08:25:27 -0600 )edit
1

Thanks for your reply. But as you can see from this docs http://docs.opencv.org/modules/core/doc/basic_structures.html that Mat::zeros is not marked as yellow. Another problem is that "zeros(Size size, int type)" seems cannot replace "zeros(int ndims, const int* sz, int type)" because the second one can create an N (N > 2) dimension matrix while the first one can't.

artanis gravatar imageartanis ( 2013-02-28 02:04:04 -0600 )edit

Excuse me, I see that I was indeed wrong. Lets see why the linker could complain further. Did you actually linked to the include folder cv2? And did you add the linker dependencies, being the different prebuilt OpenCV libraries?

StevenPuttemans gravatar imageStevenPuttemans ( 2013-02-28 02:20:03 -0600 )edit

Thanks for your reply. In my opencv 2.4.3, the libraries are under opencv\build\x64\vc10\lib, as same as default. For release version, I have added opencv_core243.lib, opencv_imgproc243.lib and opencv_highgui243.lib into VS2010's linker. I have also configured VC directories correctly since other functions except zeros(int ndims, const int* sz, int type) works well. The linker complained "unresolved reference zeros(int ndims, const int* sz, int type)"...I have also tried to build opencv by myself and use VS2012 but same problem occurs. I think it's not related my linker's setting. Because other zeros() method works well except zeros(int ndims, const int* sz, int type). And obviously they should be in the same lib file if all of them have implemented correctly. Thank you.

artanis gravatar imageartanis ( 2013-02-28 02:32:56 -0600 )edit

Just a question, did you set your target system towards x64? It is something I sometimes forget to do, resulting in not being able to open the libraries.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-02-28 02:38:49 -0600 )edit

Yeah, I think I set them correctly. Both x86 with x86 library, x64 with x64 library have been tried.

artanis gravatar imageartanis ( 2013-02-28 02:53:16 -0600 )edit

Then I have no clue anymore :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-02-28 03:07:40 -0600 )edit
0

answered 2014-10-09 01:53:13 -0600

xhpohanka gravatar image

Hi all,

it seems to me that implementation of this function is still missing in OpenCv 2.4.9.

int dims[] = { memSize, tmpFrame.rows, tmpFrame.cols };
m_samples = cv::Mat::zeros(3, dims, CV_8U);

this 3d matrix initialization gives same linker error as in @artanis post. Do I have another (simple) option to zero initialize 3d matrix?

edit flag offensive delete link more

Comments

Try grabbing the latest 2.4 branch. Artenis suggested this was fixed with a pull request.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-09 02:04:07 -0600 )edit
0

answered 2013-02-27 07:24:37 -0600

What is your OpenCV version and target platform? On Linux single pass linker is used and library order is significant.

edit flag offensive delete link more

Comments

Thanks for your reply. I am using OpenCV 2.4.3 and I have tried on both Windows (with MSVC 2012) and Linux (with the newest GCC). But on both platforms the implement of the mentioned function could not be found. What's more, in matop.cpp line 1607, I can find the implement of "zeros(int rows, int cols, int type)" and "Mat::zeros(Size size, int type)". But I cannot find the implement of "zeros(int ndims, const int* sz, int type)". I can fix it by myself (or make a pull request to fix opencv), but I need to confirm whether it really lacks implement. Could you please point out the implement of zeros(int ndims, const int* sz, int type)? Thank you.

artanis gravatar imageartanis ( 2013-02-27 09:51:19 -0600 )edit

Question Tools

Stats

Asked: 2013-02-26 23:58:51 -0600

Seen: 1,964 times

Last updated: Oct 09 '14