可视化图片
# include <opencv2/opencv.hpp>
# include <opencv2/core.hpp>
# include <filesystem>
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 ;
}