0

Its another OpenCV question. I love this stuff, but it seriously can drive you bonkers.

The problem: I am working on a project with, yes OpenCV, in iOS for iPhone. I don't know if I have a bad framework or what.

This works:

cv::Canney()
cv::adaptiveThreshold()

But, when I try

"cvGet2D()" (without previous "cv::")  

I get the error: no matching function for call to 'cvGet2D'

When I just type "cvGet2D()" it shows up in code hinting, suggesting its a least finding the headers? When I try to type "cv::get2D" or "cv::cvGet2D", nothing shows up. I'm frustrated because the OpenCV framework I installed still feels like a blackbox that I don't understand.

Specifically, do you think it could have anything do to with development vs. not and linking of the proper libraries? Just throwing things out there.

Thank you all so very much. I really appreciate and can't wait until I get smart enough to give back some.

EDIT:

So, latest attempt for clarity.

 cv::cvGet2D(results,0,0);  

New error is : "no member named "cvGet2D" in namespace 'cv';

Any ideas here?

More EDITS:

Thanks again for your responses... 4 hours later, and several cups of coffee, I'm still perplexed. If I'm screwing up the namespace, why would something like cv::adaptiveThreshold work but cv::get2D not show up? It's seriously causing a brain bleed.

So, looks like I should go with either a C or C++ version of this solution. Any tips are suggested. I will add that I have in my interface: #import <OpenCV/opencv2/opencv.hpp>. This then imports the core library where I can see cvGet2D's structure. Thanks again.

PROGRESS!!

These are my new thoughts.

cv::Mat tempMat = [self.imageView.image CVMat];
cv::Mat testMat = tempMat(cv::Rect(0,0,2591, 1)); 
cv::Mat templateMat = tempMat(cv::Rect(0,0,100,1));  

cv::Mat results; 


cv::matchTemplate(testMat, templateMat, results, CV_TM_CCOEFF_NORMED); 

typedef Vec<float, 2> Vec2f;

Vec2f& elem = results.at<Vec2f>( 0 , 35 );

float value1 = elem[0]; 
float value2 = elem[1]; 

So, perhaps it is .at that should be using? Tangent? Maybe, but it seems to be doing something. New questions, wtf does a matchTemplate output? Its 1 row and in this case 2492 columns. I guess my question is, should the value at (0,35) be more than one number? What does elem[0] and elem[1] represent? As you might be able to tell, I'm simply taking 1 row from a picture, and using a small chunk of it as the template. the photo contains vertical lines so I am hoping to determine the distance the lines are from each other. Yes, its convoluted. But, for purposes of this discussion, There really should only be 1 row, and a series of columns that outputs a correlation coefficient for each comparison as it is shifted correct?

Thanks again blokes, mates, lads, lasses, and all you smart masses!

justagruvn
  • 337
  • 5
  • 8
  • Now you are asking an entirely different question. Stack Overflow follows the one-answer-per-question style, so if you keep changing the question, is not fair to those who are trying to help you. The right procedure should be: revert your question to the previous one, select the answer that solved it, and ask a new question in a new thread. – karlphillip Jun 06 '12 at 13:48

3 Answers3

1

You're probably using C++ API of OpenCV 2.0.

Functions were moved to cv namespace.

You can use them with preceeding cv:: or by simply adding using namespace cv; to the beggining of the file where you use them.

Reference: http://www.aishack.in/2010/07/opencvs-c-interface/

EDIT:

also make sure you have all the capital letters correct:

it should compile if you use cv::cvGet2D(img,i,j) or (if you include namespace) simply cvGet2D(img,i,j)

Rok Jarc
  • 18,765
  • 9
  • 69
  • 124
  • Thanks for the quick reply! When I use "cv::get2D" it doesn't register as a function. Whats weird is that it does work for "cv::canny" and "cv::adaptiveThreshold". – justagruvn Jun 05 '12 at 20:48
  • shouldn't here be a capital G? - cv::cvGet2D(img,i,j) is not the same as cv:get2D or cv:cvget2D – Rok Jarc Jun 05 '12 at 20:59
  • thanks again for your response... 4 hours later, and several cups of coffee, I'm still perplexed. – justagruvn Jun 06 '12 at 01:10
1

First of all, there's no such thing as cv::cvGet2D().

The name cvGet2D() indicates that it belongs to the C interface of OpenCV, however, you seem to be using the C++ interface. It's not good to mix them, you know. FYI, this function is available in the opencv_core library.

The error message tells you that it was unable to find this function in the headers you've declared, so it seems that you are missing the right header. Try to #include <cv.h>.

EDIT:

Due to your newest update on the question, I must also add that there's also no such thing as cv::get2D(). Stop trying to put namespaces around cvGet2D(), this is a function from the C interface, there's no namespace in the C language.

karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • I really appreciate your responses. So, I'm pretty obviously new to this. I tried including and it didn't seem to fix anything. It just blows my mind that it can code hint for cvGet2D, but then when you fill out the fields, it says it can't find the function. Do you have any ideas why it is doing that? I c in the documentation under the core for C, but I'm using C++?. I know you're going to puke, have a seizure, lose bowel control for the stupidity in this question, but if I don't want to mix them do you have suggestion? I am trying to read results of cvMatchTemplate gives 1 col mny row – justagruvn Jun 06 '12 at 03:04
  • Why don't you simple use the C interface, or the C++ interface? Both implement basically the same functionality. The C++ interface provides some extra cool extra, though. These interfaces shouldn't be mixed. It will cause problems and confusion. – karlphillip Jun 06 '12 at 03:12
  • I think I'm so clueless I don't even know which one I'm using. How would I do it using C++? What would be different? I think my confusion comes because I'm already using some form of Objective C in Xcode right, so then I start trying to add these other things in and it just gets messy for a noob. – justagruvn Jun 06 '12 at 03:17
  • When you see the namespace operator `::` being used, it's C++. Check [this post](http://stackoverflow.com/a/10907010/176769) for example. You might be using `Mat` in your code, this is a data type from the C++ interface of OpenCV as well, while `IplImage` is its equivalent on the C interface. Don't forget to up vote posts that helped you somehow. – karlphillip Jun 06 '12 at 03:43
  • Updated Question. I don't know if it will let me upgrade answers. If someone else can upgrade this Karl has been the Utmost AWESOMEST!!!! – justagruvn Jun 06 '12 at 03:53
0

How about using Mat_ class? It can be cast from Mat.

Mat_<Vec3b>& M_ = (Mat_<Vec3b>&)M;
for(int i = 0; i < M_.rows; i++)
    for(int j = 0; j < M_.cols; j++)
        M_(i,j) = cv::Vec3b(0,255,0); // Fill Green

See also

http://docs.opencv.org/modules/core/doc/basic_structures.html#id7

ITO Yosei
  • 949
  • 2
  • 8
  • 21