日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

在進行圖像處理的時候,經常要進行圖像的剔除。下面我們學習一下opencv刪除圖像的函數。

//int result = remove(img_path[i].c_str()); //絕對或者相對路徑都可以

int result = remove("1.jpg"); //絕對或者相對路徑都可以

if (result == 0)

cout << "delete succeeded!刪除圖片成功" << endl;

else

cout << "delete failed! 刪除圖片失敗" << endl;

具體應用示例

為了方便大家理解如何使用,下面我舉一個例子,在相機標定的時候進行圖像不符合規范的自動刪除

#include "opencv2/core/core.hpp"    
#include "opencv2/imgproc/imgproc.hpp"    
#include "opencv2/calib3d/calib3d.hpp"    
#include "opencv2/highgui/highgui.hpp"    
#include <IOStream>    
#include <fstream>    
#include <iostream>

#include <stdlib.h> //srand()和rand()函數 
#include<windows.h>

using namespace cv;
using namespace std;


#define  debug_show_picture        1 //是否顯示部分調試圖片,方便調試
#define  debug_save_shipin       0 //是否保存結果視頻

/****************	     打印相關組件 start !	 ********************************************************************/

/*打印等級,修改后面的宏定義可以改變函數輸出打印等級*/
#define ALG_PRTINT_LEVER PRINT_LEVEL_UNLIMIT

#define ALG_PRTINT(...)  SAL_printf(__VA_ARGS__)
#define ALG_PRT(...)     ALG_PRTINT(__FUNCTION__, __LINE__, PRINT_LEVEL_UNLIMIT, __VA_ARGS__)
#define ALG_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_LEVEL_E_
{
	PRINT_LEVEL_ERR = 0,        /*錯誤打印信息*/
	PRINT_LEVEL_WRN = 1,        /*警告打印信息*/
	PRINT_LEVEL_DBG = 2,         /*調試打印信息*/
	PRINT_LEVEL_UNLIMIT = 3,    /*無限制打印信息*/
	PRINT_LEVEL_NOPRT = 4,      /*沒有打印信息*/
} PRT_LEVEL_E;

/*******************************************************************************
Function:	SAL_printf
Description: 該函數能夠通過設置的打印等級ALG_PRTINT_LEVER,來控制是否輸出相關語句
Input:
Output:
Return:
0:			Successful
ohters:		Failed
*******************************************************************************/
void SAL_printf(const char *pFun, UINT line, PRT_LEVEL_E levelParam, const 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("[ALG][%s][%s][%4d] ", g_printfInfo[levelParam], 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 folder
	for (size_t i = 0; i < count; i++)
	{
		temp.push_back(fn[i]);
	}
	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[i]);
		if (imageInput.empty())
		{
			ALG_ERR("can not open pic,圖片 %s 打開失敗n", img_path[i].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("輸出結果:%sn", 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[i].c_str());
			int result = remove(img_path[i].c_str());  //絕對或者相對路徑都可以
			if (result == 0)
				cout << "delete succeeded!刪除圖片成功" << endl;
			else
				cout << "delete failed! 刪除圖片失敗" << endl;

			continue;
		}
		else
		{
			ALG_PRT("正在提取圖片%s的角點,image_count=%dn", img_path[i].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[i].x;
				p2.y = image_points_buf[i].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 
}

分享到:
標簽:語言
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定