c语言中文版删除图片在进行图像处理的时候,经常要进行图像的剔除。下面我们学习一下中文版删除图像的函数。
//int result=remove(img _ path。c _ str());//绝对或者相对路径都可以int result=remove(' 1。jpg’);//绝对或者相对路径都可以if (result==0)cout 'delete成功!删除图片成功“结束”删除失败!删除图片失败恩德尔具体应用示例为了方便大家理解如何使用,下面我举一个例子,在相机标定的时候进行图像不符合规范的自动删除
# include ' opencv 2/core/core。HPP ' # include ' opencv 2/imgproc/imgproc。HPP ' # include ' opencv 2/calib3d/calib3d。HPP ' # include ' opencv 2/high GUI/high GUI。HPP ' # include iostream # include fstream # include iostream # include stdlib。h//srand()和兰德()函数#includewindows.husing命名空间cv;使用命名空间STD # define debug _ show _ picture 1//是否显示部分调试图片,方便调试#define debug_save_shipin 0 //是否保存结果视频/**************** 打印相关组件开始!********************************************************************//*打印等级,修改后面的宏定义可以改变函数输出打印等级*/# define ALG _ pr tint _ LEVER PRINT _ LEVEL _ un limit # define ALG _ pr tint(.)SAL _ printf(_ _ VA _ ARGS _ _)#定义PRT阿尔及利亚(.)ALG_PRTINT(__FUNCTION__,__LINE__,PRINT_LEVEL_UNLIMIT,_ _ VA _ ARGS _ _)#定义DBG阿尔及利亚(.)ALG_PRTINT(__FUNCTION__,__LINE__,PRINT_LEVEL_DBG,__VA_ARGS__)#define ALG_WAR(.)ALG_PRTINT(__FUNCTION__,__LINE__,PRINT_LEVEL_WRN,__VA_ARGS__)#define ALG_ERR(.)ALG_PRTINT(__FUNCTION__,__LINE__,PRINT_LEVEL_ERR,_ _ VA _ ARGS _ _)/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * enum HAT _ SAL _ PRT _ LEVEL _ E * @ brief打印输出的等级* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */typedef enum _ PRT _级别_ E _ {打印_级别_错误=0,/*错误打印信息*/打印级别WRN=1,/*警告打印信息*/打印级别DBG=2,/*调试打印信息*/PRINT_LEVEL_UNLIMIT=3,/*无限制打印信息*/PRINT _ LEVEL _ no port=4,/*没有打印信息*/} PRT _ LEVEL _ E; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *函数: sal _ printfdescription :该函数能够通过设置的打印等级ALG_PRTINT_LEVER,来控制是否输出相关语句输入:输出:返回:0:成功其他:失败* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */void SAL _ printf(const char * pFun,UINT line,PRT_LEVEL_E levelParam,co
nst char *fmt, ...){static INT8 g_printfInfo<4><16> = { "ERR", "WAR", "DBG", "INF" };va_list p;if (ALG_PRTINT_LEVER == PRINT_LEVEL_NOPRT || levelParam == PRINT_LEVEL_NOPRT){return;}if (levelParam <= ALG_PRTINT_LEVER){va_start(p, fmt);printf(" <%s><%s><M> ", g_printfInfo , pFun, line);vprintf(fmt, p);va_end(p);}}/****************************** 打印相关组件 end *************************************************************************/class Ve{public:vector<string> ReadImage(cv::String pattern);};vector<string> Ve::ReadImage(cv::String pattern){vector<string> temp;vector<cv::String> fn;glob(pattern, fn, false);size_t count = fn.size(); //number of png files in images folderfor (size_t i = 0; i < count; i ){temp.push_back(fn );}return temp;}void main(){ofstream fout("caliberation_result.txt"); /* 保存标定结果的文件 *///读取每一幅图像,从中提取出角点,然后对角点进行亚像素精确化 cout << "开始提取角点………………\n";int image_count = 0; /* 图像数量 */Size image_size; /* 图像的尺寸 */Size board_size = Size(8, 11); /* 标定板上每行、列的角点数 */vector<Point2f> image_points_buf; /* 缓存每幅图像上检测到的角点 */vector<vector<Point2f>> image_points_seq; /* 保存检测到的所有角点 */int count = -1;//用于存储角点个数。 //while (getline(fin, filename))//{cv::String pattern = "./data/0223_2che/2che_huoche_video4/*.jpg";Ve ve;vector<string> img_path = ve.ReadImage(pattern);for (int i = 0; i < img_path.size(); i ){image_count ;// 用于观察检验输出 //cout << "image_count = " << image_count << endl;/* 输出检验*///cout << "-->count = " << count << endl;Mat imageInput = imread(img_path);if (imageInput.empty()){ALG_ERR("can not open pic,图片 %s 打开失败\n", img_path.c_str());cout << "can not open pic!\n";Sleep(100000);//睡眠一下,不至于窗口跳出exit(-1);}Mat imageInput_copy = imageInput.clone(); //校正后输出图片if (image_count == 1) //读入第一张图片时获取图像宽高信息 {image_size.width = imageInput.cols;image_size.height = imageInput.rows;cout << "image_size.width = " << image_size.width << endl;cout << "image_size.height = " << image_size.height << endl;}//printf("输出结果:%s\n", filename.c_str());/* 提取角点 */if (0 == findChessboardCorners(imageInput, board_size, image_points_buf)){cout << "can not find chessboard corners!\n"; //找不到角点ALG_ERR("图片: %s 找不到角点,请检查或者更换该图片\n", img_path.c_str());int result = remove(img_path.c_str()); //绝对或者相对路径都可以if (result == 0)cout << "delete succeeded!删除图片成功" << endl;elsecout << "delete failed! 删除图片失败" << endl;continue;}else{ALG_PRT("正在提取图片%s的角点,image_count=%d\n", img_path.c_str(), image_count);Mat view_gray;cvtColor(imageInput, view_gray, COLOR_RGB2GRAY);/* 亚像素精确化 */find4QuadCornerSubpix(view_gray, image_points_buf, Size(5, 5)); //对粗提取的角点进行精确化 //cornerSubPix(view_gray,image_points_buf,Size(5,5),Size(-1,-1),TermCriteria(CV_TERMCRIT_EPS CV_TERMCRIT_ITER,30,0.1)); image_points_seq.push_back(image_points_buf); //保存亚像素角点 /* 在图像上显示角点位置 */drawChessboardCorners(view_gray, board_size, image_points_buf, false); //用于在图片中标记角点 namedWindow("Camera Calibration", 0);//创建窗口imshow("Camera Calibration", view_gray);//显示图片 waitKey(5);//暂停0.5S //这种初始化点的方式也可以for (int i = 0; i < image_points_buf.size(); i ){Point p2;p2.x = image_points_buf.x;p2.y = image_points_buf.y;//画实心点circle(imageInput_copy, p2, 8, Scalar(0, 0, 255), -1); //第五个参数我设为-1,表明这是个实点。}namedWindow("imageInput_copy", 0);//创建窗口imshow("imageInput_copy", imageInput_copy);//显示图片 waitKey(5);//暂停0.5S }}ALG_PRT("所有图片检查完毕\n");waitKey(5000000000000);//暂停0.5S } 以上就是帮企客小编为大家带来的全部内容,希望可以帮助到大家。免责声明:本文为转载,非本网原创内容,不代表本网观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
如有疑问请发送邮件至:bangqikeconnect@gmail.com