Fastest way to check if a value exist using standard C++
I often have to test whether a class "exists"
Do something IF cv::Rect is not empty/nil?
Do something IF cv::Mat is not empty/nil?
In Objective-C is easy:
If(someObject){
// the object exist so do what you want
}
is there any possible way to test simply these classes?
Today i do this:
If(myMat.rows != 0){
// My Mat is not empty
}
OR
If(myRect.width != 0){
// My Rect is not empty
}
is there another way to do this?
in general, with classes, checking their mere existance is probably not helpful, you want to know, if they are in a valid state.
Mat
and Rect,and many other classes (esp. cv::Ptr) have anemtpy()
method.other classes, that load resources, like VideoCapture or CascadeClassifier, have an
isOpened()
method for that.I cannot see the the
empty()
method on thecv::Rect
variable, but I can see anarea()
method, that may be used for verification (> 0). Anyway, what does "Rect is not empty" means? It contains 4 ints... You can draw aRect(5, 5, -1, -2)
. I think you shall do a method that says if your rectangle is valid or not, based on its members, or maybe based on the image size and its size and position (eg:roi & imgRect == roi
)^^ thanks, i was wrong.
Thanks for the help, however "I" consider a Rect empty when its size width and height are null, anyway it would have been interesting to have a bool connected to the object.
Rect I do not think it can have null values, it contains int members