0

I have a completed, 100% working OpenCV C++ program that I wanted to add WinForms functionality to. After importing all of the libraries and includes:

#pragma once
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
#include <stdlib.h>


namespace CoinCounterProgramMelee {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace cv;
using namespace std;

I pasted my OpenCV code into the .h file for the Form. An error occurred whenever I would create a vector of vectors of Points, e.g:

vector<vector<Point>> contours;

The problem is in the , as Visual Studio is saying that Point is ambiguous.

Errors also come up whenever I call Size(). Can anyone tell me what the problem is? Sorry if there are any problems with this question, I don't use StackOverflow very often.

Thanks

  • 2
    This is why you don't use `using namespace ...`. `using namespace` in a header file is particularly bad. – john Aug 02 '22 at 11:44
  • what is the complete error message? Usually when something is ambiguous the message tells you what the alternatives are – 463035818_is_not_an_ai Aug 02 '22 at 11:44
  • *Can anyone tell me what the problem is?* `using namespace` – Eljay Aug 02 '22 at 11:47
  • 3
    its like you invite 5000 guests to a party, ignore their last names, and expect that there is only one person called Mary. It might work or it might not work – 463035818_is_not_an_ai Aug 02 '22 at 11:47
  • In this particular case it's `using namespace cv;` and `using namespace System::Drawing;` – john Aug 02 '22 at 11:49
  • I commented out `using namespace System::Collections;`, `using namespace System::Data;` and `using namespace System::Drawing;`. This solved the vector errors, however, the 2 errors with size (call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type) still exist. Is there something else I should comment out or add? – shave_your_eyebrows Aug 02 '22 at 12:45
  • @shave_your_eyebrows Without seeing the code that is causing that problem it's very hard to say. – john Aug 02 '22 at 13:37
  • @john `Mat kernel = getStructuringElement(MORPH_RECT, Size(3, 3));` and `GaussianBlur(imgGrey, imgBlur, Size(3, 3), 3, 0);` are the only things bringing up errors now (the same call of an object and class type thingy I mentioned in my last comment) – shave_your_eyebrows Aug 02 '22 at 14:53
  • @shave_your_eyebrows I've not sure without a bit more context. I would guess that the `Size` type is ambiguous because of the remaining `using namespace ...;` you have. Have you tried fully qualifying `Size` (i..e using it's fully qualified name with all the namespaces). You should do that as a test, but really you should be rewriting your code to never use `using namespace ...;`. You know that you can just use `using X::Y;` where X is a namespace and Y is a class within that namespace? That avoids many of these problems. Or you can just fully qualify your names everywhere. Or a mix of the two – john Aug 02 '22 at 15:05
  • @john Putting in `using cv::size;` just above the first use of size in main() completely fixed it. Thanks a bunch, you really saved me :) – shave_your_eyebrows Aug 02 '22 at 16:25

0 Answers0