In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about what the auxiliary object in OpenCV refers to. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
1. TermCriteria class
Many algorithms in OpenCV require a termination condition to determine when to exit. Usually the termination condition is in the form of either a limited number of allowed iterations (called COUNT or MAX_ITER) or some form of error parameter (if it is close to this level, it can be exited, called EPS, or epsilon for short). In the program, it can be set through the public variable of TermCriteria, of course, the most commonly used is through its constructor.
TermCriteria (int type, int maxCount, double epsilon)
Where type is set to COUNT or EPS, or it can be used at the same time (with | connection). After setting up type, you also need to set up the corresponding maxCount or epsilon.
2. Range class
The Range class is used to determine a contiguous sequence of integers, and the Range object has two elements, start and end, similar to the TermCriteria above, and is usually set in the constructor.
Cv::Range (int start, int end)
The range of this Range includes the initial value start, but does not include the termination value end. There are two member functions in this class, one is empty () to test whether a range is empty, and the other is all (), which is used to get the available scope of the object.
3. Ptr templates and garbage collection
We know that smart pointers are a very useful type in C++. This pointer allows us to create a reference to an object, and then pass it around the world, create more references to the object, and then these references will be counted, when the reference is out of scope. The smart pointer's reference count is reduced, and once all references disappear, the object is automatically cleaned up and released. And as programmers, we don't have to record these things.
Next, let's learn how it works. First, we need to define an instance of the pointer template for the class object we want to encapsulate. This can be achieved by calling the following:
Cv::Ptr p (new cv::Matx33f)
Or
Cv::Ptr p = makePtr ()
Once implemented, you have a smart pointer p that can be used as a standard pointer, such as the supporting operators * and->. Once we have p, we can create other objects of the same type without passing them a pointer to the new object.
For example, like creating a Ptr Q, when you pass the value of p to Q, somewhere in the background, the smart pointer starts counting. You can use it like a normal pointer, but there is actually only one instance of Mat33f, and p and Q point to it at the same time. When p is released beyond the life cycle, Q knows that it is the only reference to the original matrix, and if the life cycle of Q ends, the original matrix will be released. It's kind of like closing the door and turning off the lights when the last student in the classroom leaves.
The cv::Ptr () template class has some member functions to learn about:
Addref () and release () increase and decrease the reference count inside the pointer (with caution).
The empty () function is used to determine whether a smart pointer points to an object that has been released.
The delete_obj () function, which is called automatically after the reference is zeroed, needs to be overloaded when customizing the type and is used to release the object.
Let's learn about the application of smart pointers through an example.
Here we create a smart pointer to FILE, and here we need to overload the delete_obj () function for the Ptr template.
Template inline void cv::Ptr::delete_obj ()
{
Fclose (obj)
}
Next, you can use this pointer to do something without releasing it yourself when you leave the range, as follows:
{
Cv::Ptr f (fopen ("myfile.txt", "r"))
If (f.empty ())
Throw...; / / Throw an exception, we will get to this later on...
Fprintf (f,...)
...
}
That is to say, at the end of the curly braces, f leaves the scope, and the reference count inside f becomes 0. The reference count within f is called by the destructor of f, automatically freeing memory.
4. Exception class and exception handling
OpenCV handles errors with exceptions, and OpenCV defines its own exception class cv::Exception, which inherits from STL's std::exception. The Exception type has members code,err,func,file and line, which respectively refer to the error code corresponding to a number, the string that produced the exception error, the name of the function in which the error occurred, the file in which the error occurred and the number of lines in the file where the error occurred. Both err,func and file are STL strings.
There are several built-in macros for generating your own exceptions. CV_Error (errorcode, description) generates and throws an exception with a fixed text description. Both CV_Assert (condition) and CV_DbgAssert (condition) test the conditions set in the program, and throw an exception if the conditions are not met. These macros are the preferred way to throw exceptions because they automatically handle functions, files, and lines for you.
5. DataType template
When OpenCV library functions need to pass the concept of a specific data type, they create an object of type DataType, DataType itself is a template, and the actual object passed is a specialization of the template.
6. InputArray class and OutputArray class
Many OpenCV functions take arrays as variables and arrays as return values, but there are all kinds of arrays in OpenCV. We have learned that OpenCV supports some small array types, such as Scalar,Vec,Matx, as well as std::vector and the large arrays discussed later (Mat and SparseMat). To prevent the interface from becoming complex, OpenCV defines the InputArray class and the OutputArray class, which means "any of the above".
In fact, the main difference between InputArray and OutputArray is that the former is assumed to be constant (read-only), followed by variables. Associated with InputArray is the special function noArray (), whose return value can be used wherever InputArray is needed to emphasize inputs that are not used, and some functions have optional output arrays that can be passed noArray () when the corresponding output is not needed.
After reading the above, do you have any further understanding of what helper objects refer to in OpenCV? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.