本文介绍了获取OpenCV映像类型的枚举名称(例如CV_32FC1)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在OpenCV的C ++接口中,看起来很容易检查图像的类型。如果你有一个图像 cv :: Mat img = cv :: imread(someImage.xyz),你只需要做 int theType = img。 type()。 但是,如你所料,调用 img.type()只是给出一个整数,有一个简单的方法打印出枚举名称(例如 CV_32FC1 )。 CV_32FC1 )如果我知道OpenCV枚举的整数值? 解决方案据我所知,OpenCV中不存在这样的函数。 我认为你最好写自己的函数来获得这些。很多开关箱,但我猜它做的工作。可以在此处找到枚举 这是您可以用来提取类型。我猜想可能有一个更有效的方法,但我现在不能包装我的头。 std :: string getImageType(int number) { //查找类型 int imgTypeInt = number%8; std :: string imgTypeString; switch(imgTypeInt) { case 0: imgTypeString =8U; break; case 1: imgTypeString =8S; break; case 2: imgTypeString =16U; break; case 3: imgTypeString =16S; break; case 4: imgTypeString =32S; break; case 5: imgTypeString =32F; break; case 6: imgTypeString =64F; break; 默认值: break; } //找到通道 int channel =(number / 8)+ 1; std :: stringstream type; type<<CV _<< imgTypeString<<C<< return type.str(); } In the C++ interface to OpenCV, it seems easy enough to check the type of an image. If you have an image cv::Mat img = cv::imread("someImage.xyz"), you just do int theType = img.type(). However, as you would expect, calling img.type() just gives an integer, an not an enum name (e.g. CV_32FC1).Is there an easy way to print out the enum name (e.g. CV_32FC1) if I know the integer value of the OpenCV enum? 解决方案 To my knowledge, such a function doesn't exist in OpenCV. I think you would be better off writing your own function to get those. A lot of switch cases but I guess it does the job. The enumeration can be found here.EDIT: This is something you could use to extract the types. I am guessing there could be a more efficient method, but I can't wrap my head around it right now. std::string getImageType(int number){ // find type int imgTypeInt = number%8; std::string imgTypeString; switch (imgTypeInt) { case 0: imgTypeString = "8U"; break; case 1: imgTypeString = "8S"; break; case 2: imgTypeString = "16U"; break; case 3: imgTypeString = "16S"; break; case 4: imgTypeString = "32S"; break; case 5: imgTypeString = "32F"; break; case 6: imgTypeString = "64F"; break; default: break; } // find channel int channel = (number/8) + 1; std::stringstream type; type<<"CV_"<<imgTypeString<<"C"<<channel; return type.str();} 这篇关于获取OpenCV映像类型的枚举名称(例如CV_32FC1)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 00:13