c++ - cv::Mat , get value at row column without knowing the type of the matrix -
c++ - cv::Mat , get value at row column without knowing the type of the matrix -
so trying value of matrix, type not know, using row , column value. want implement following:
bool somefunction(cv::mat m){ homecoming m(1,0) != 0; } i know error out since need specify type m.at< type >(1,0) not know type.
i tried doing following: m.at< m.type() >(1,0) that, of course, errors out.
i wondering potentially work here. thanks!
a not elegant solution. utilize depth , switch case.
#include<cv.h> #include<stdint.h> using namespace cv; using namespace std; bool somefunction(mat m) { switch (m.depth()){ case cv_8u: homecoming m.at<uint8_t>(1,0) != 0; case cv_8s: homecoming m.at<int>(1,0) != 0; case cv_16u: homecoming m.at<uint16_t>(1,0) != 0; case cv_16s: homecoming m.at<int16_t>(1,0) != 0; case cv_32s: homecoming m.at<int32_t>(1,0) != 0; case cv_32f: homecoming m.at<float>(1,0) != 0; case cv_64f: homecoming m.at<double>(1,0) != 0; } } int main() { mat m(2,2, cv_8uc1); cout << somefunction(m) << endl; } c++ opencv matrix
Comments
Post a Comment