I don’t know, maybe I’m terribly slowing down, but I don’t quite understand how to fix it.
There is some class. Let's say it's called MyClass . There is a cv::VideoCapture camera; declared in MyClass . The cv::VideoCapture is used to capture video from video files and video streams from video cameras.
There is, for example, in MyClass some open method camera_open(); . And there is a main entry point.
The question is this:
- If you directly register
camera.open(0);inmaincamera.open(0);and thencamera.release();, to clean, then all is well; - If in the
maincallcamera_open(), which already containscamera.open(0);andcamera.release();, then an error occurs during the execution of the program related to read access rights.
Why and how to get rid of it, leaving the scheme with a call to the camera_open() method?
That is, it should be like this:
int _tmain(int argc, _TCHAR* argv[]) { MyClass mc; mc.camera_open(); return 0; } void MyClass::camera_open() { camera.open(0); // действия camera.release(); } More specifically, I now have this:
int _tmain(int argc, _TCHAR* argv[]) { MyClass mc; mc.ComputerVision(); // это и есть абстрактный camera_open return 0; } // не указан сервер, не указана директория, не указано время void MyClass::ComputerVision() { if (camera_open()) Start(desktop_directory()); } void MyClass::ComputerVision(std::string str, short mode) { if (mode == 0) // указан сервер, не указана директория, не указано время { if (camera_open(str)) Start(desktop_directory()); } else // указана директория, не указан сервер, не указано время { if (camera_open()) Start(str); } } // указаны сервер и директория, не указано время void MyClass::ComputerVision(std::string server, std::string directory) { if (camera_open(server)) Start(directory); } // указано время, не указан сервер, не указана директория void MyClass::ComputerVision(double time) { userTime = time; ComputerVision(); } // указано время и указана либо директория, либо сервер void MyClass::ComputerVision(double time, std::string str, short mode) { userTime = time; ComputerVision(str, mode); } // указано время, указан сервер, указана директория void MyClass::ComputerVision(double time, std::string server, std::string directory) { userTime = time; ComputerVision(server, directory); } // открытие камеры по умолчанию boolean MyClass::camera_open() { try { camera.open(0); server = ""; } catch (std::exception) { std::cout << std::endl << "Failed to connect to your web camera"; return false; } return true; } // открытие камеры по указанному серверу boolean MyClass::camera_open(std::string server) { try { camera.open(server); this->server = server; } catch (std::exception) { std::cout << std::endl << "Failed to connect to IP camera"; return false; } return true; } Both camera_open(...) private, the rest is public. An error occurs on camera.open(...); .
main()or in the method of an arbitrary class - there is no difference, it should work the same. Update the question and provide a full listing of the minimum project at which the error occurs. - alexis031182