可视化图片
#include
#include
#include
std::string opencvTool::type2str(int type)
{
std::string r;
uchar depth = type & CV_MAT_DEPTH_MASK;
uchar chans = 1 + (type >> CV_CN_SHIFT);
switch (depth)
{
case CV_8U: r = "8U"; break;
case CV_8S: r = "8S"; break;
case CV_16U: r = "16U"; break;
case CV_16S: r = "16S"; break;
case CV_32S: r = "32S"; break;
case CV_32F: r = "32F"; break;
case CV_64F: r = "64F"; break;
default: r = "User"; break;
}
r += "C";
r += (chans + '0');
return r;
}
bool opencvTool::showImage(std::string image_p)
{
cv::Mat image = cv::imread(image_p.c_str());
if (image.empty())
{
std::cout << "Error: empyt mat " << std::endl;
return false;
}
std::cout << "Image size: " << image.cols << " x " << image.rows << std::endl;
std::cout << "Number of channels: " << image.channels() << std::endl;
std::cout << "Data type: " << type2str(image.type()) << std::endl;
cv::imshow("test", image);
cv::waitKey(0);
cv::destroyAllWindows();
return true;
}
bool opencvTool::showImage(cv::Mat image)
{
if (image.empty())
{
std::cout << "Error: empty mat " << std::endl;
return false;
}
std::cout << "Image size: " << image.cols << "x" << image.rows << std::endl;
std::cout << "Number of channels: " << image.channels() << std::endl;
std::cout << "Data type: " << type2str(image.type()) << std::endl;
cv::imshow("test", image);
cv::waitKey(0);
cv::destroyAllWindows();
return true;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66