fork(1) download
  1. #include <opencv2/core/core.hpp> // coreモジュールのヘッダーをインクルード
  2. #include <opencv2/highgui/highgui.hpp> // highguiモジュールのヘッダーをインクルード
  3. #include <opencv2/imgproc/imgproc_c.h> // imgprocモジュールのC版ヘッダーをインクルード
  4. #include <windows.h>
  5. #include <string.h>
  6. #include <iostream>
  7. #include <tchar.h>
  8. #include <shlwapi.h>
  9. #include <limits.h>
  10. #include <time.h>
  11. //#include <wingdi.h>
  12. //#include <shlobj.h>
  13. #pragma comment(lib,"shlwapi.lib")
  14. #pragma comment(lib, "setupapi.lib")
  15. #pragma comment(lib, "hid.lib")
  16. #pragma comment(lib, "winmm.lib")
  17. #define S_BITMAP 1
  18. #define S_PXM 2
  19. #define S_PNG 3
  20. #define S_JPG 4
  21. #define EXTENCTION_LEN 6
  22. #define FPS_LIMITS 60.0
  23. #define GRAY_SCALED 1
  24. #define THRESHOLDING 2
  25. #define FILE_NAME_LEN 50//毎秒60枚取るとして7桁あれば40時間以上撮影可能。ファイル名重複対策に2桁、バックスラッシュに1桁、予備4桁で25桁
  26. #define FILE_NAME_SUB_LEN 18//毎秒60枚取るとして7桁あれば40時間以上撮影可能。ファイル名重複対策に2桁、バックスラッシュに1桁、予備4桁で17桁
  27. typedef struct _PARAM{
  28. int jpeg_quality[2];//-q
  29. int png_compression[2];//-c
  30. int pxm_binary[2];//-b
  31. }PARAM;
  32. typedef struct _PROCESS_CONF{
  33. PARAM param;
  34. bool use_param;//-enable-ad-conf
  35. double threshold;//二値化のしきい値。0なら大津のアルゴリズムを使用(default = 0)
  36. short ppm_magic;//pxm_binary依存
  37. short pic_type;//-p
  38. short process_mode;//-edit
  39. unsigned int frame_num;//-f
  40. double frame_rate;//-fps
  41. unsigned int core_filename_num;//-n
  42. }PROCESS_CONF;
  43. void print_help(void) {
  44. fprintf(stdout, ""
  45. "Scatto_continuo.exe [options...] [-enable-ad-conf [aditional option(s)]] \n"
  46. "All parameter must be specified as an Intenger type without \"-fps\" and \"-th\""
  47. " option(s)...\n"
  48. " -h print help\n"
  49. "\n"
  50. " -p [type] set picture format\n"
  51. " [type] : bmp, ppm, pgm, pbn, png, jpg\n"
  52. " -f [num] set how many times you want to capture.\n"
  53. " -fps [0-60] set fps<double>.\n"
  54. " When you set \"23.97\", \"29.97\" or \"59.94\", we will use more accurate value.\n"
  55. " -edit [0-2] set picture process mode\n"
  56. " [num] :0:do anything.1:to grayscaled. 2:to thresholded. \n"
  57. " If you use \"-p pgm\" or \"-p pbm\", \"-edit\" will be disable.\n"
  58. "\n"
  59. " -enable-ad-conf enable a group of options listed below"
  60. "\n"
  61. " aditional option(s)\n"
  62. " -b [mode] set PPM save_mode(binary : 1(default) / ascii : 0)\n"
  63. " -c [level] set PNG complession level.\n"
  64. " -q [quality] set JPG quality\n"
  65. "\n"
  66. " -n \"core_name\" set core_name.\n"
  67. " Output-filename will be \"[core_name][num]_[num].[type]\"\n"
  68. " -th [1-254] You specify a threshold<double>,\n"
  69. " and disable the Otsu's algorithm\n"
  70. "\n"
  71. "We will caputure and set core_name caputure and save as bitmap image only once when there is no command line arguments");
  72. exit(0);
  73. }
  74. void print_command_line_error(int place = 0){
  75. printf("invalid option(s).\n"
  76. "place:%d", place);
  77. print_help();
  78. }
  79. int getnum(void){
  80. char s[100];
  81. long t;
  82. char *endptr;
  83.  
  84. fgets(s, 100, stdin);
  85. errno = 0;
  86. t = strtol(s, &endptr, 10);
  87. if (errno != 0 || *endptr != '\n' || (t < INT_MIN || INT_MAX < t))
  88. return -1;
  89. return t;
  90. }
  91. int sgetnum(const char *s, const long max = INT_MAX, const long min = INT_MIN){
  92. long t;
  93. char *endptr;
  94. errno = 0;
  95. t = strtol(s, &endptr, 10);
  96. if (errno != 0 || t < min || max < t || t < INT_MIN || INT_MAX < t)
  97. return -1;
  98. return (int)t;
  99. }
  100. double sgetnum_d(const char *s, const long double max = DBL_MAX, const long double min = DBL_MIN){
  101. long double t;
  102. char *endptr;
  103. errno = 0;
  104. t = strtod(s, &endptr);
  105. if (errno != 0 || t < min || max < t || t < DBL_MIN || DBL_MAX < t)
  106. return -1;
  107. return (double)t;
  108.  
  109. }
  110. //==============================================================
  111. // [概要]
  112. // wchar_t* から char* への変換を行う
  113. // [引数]
  114. // pSrc const wchar_t* 変換するwchar_t型の文字列。
  115. // pDest char* 変換結果のchar型文字列。
  116. // sDestSize const size_t pDestのサイズ
  117. // [戻り値]
  118. // int 0:正常,-1:異常
  119. //==============================================================
  120. int wchartToChar(const wchar_t* pSrc, char* pDest, const size_t sDestSize)
  121. {
  122. size_t iReturnValue;
  123. errno_t ret = wcstombs_s(&iReturnValue, pDest, sDestSize, pSrc, _TRUNCATE);
  124. if (ret != 0) return -1;
  125. return 0;
  126. }
  127. //==============================================================
  128. // [概要]
  129. // char* から wchar_t* への変換を行う
  130. // [引数]
  131. // pSrc const char* 変換するchar型の文字列。
  132. // pDest wchar_t* 変換結果のwchar_t型文字列。
  133. // sDestSize const size_t pDestのサイズ
  134. // [戻り値]
  135. // int 0:正常,その他:異常
  136. //==============================================================
  137. int charToWchart(const char* pSrc, wchar_t* pDest, const size_t sDestSize)
  138. {
  139. size_t iReturnValue;
  140. errno_t ret = mbstowcs_s(&iReturnValue, pDest, sDestSize, pSrc, _TRUNCATE);
  141. if (ret != 0) return ret;
  142. return 0;
  143. }
  144. int Determine_Filename(const int roop_turn, TCHAR *tfilename, TCHAR * tcore_filename, const short pic_type, const short ppm_magic = 6){
  145. TCHAR crDir[MAX_PATH + FILE_NAME_LEN + 1];//毎秒60枚取るとして7桁あれば40時間以上撮影可能。ファイル名重複対策に2桁、バックスラッシュに1桁、予備4桁
  146. int i = 0;
  147. TCHAR pic_extension[EXTENCTION_LEN];
  148. switch (pic_type)
  149. {
  150. case S_BITMAP:
  151. _stprintf_s(pic_extension, EXTENCTION_LEN, __T("bmp"));
  152. break;
  153. case S_PXM:
  154. switch (ppm_magic)
  155. {
  156. case 1:
  157. case 4:
  158. _stprintf_s(pic_extension, EXTENCTION_LEN, __T("pbm"));
  159. break;
  160. case 2:
  161. case 5:
  162. _stprintf_s(pic_extension, EXTENCTION_LEN, __T("pgm"));
  163. break;
  164. case 3:
  165. case 6:
  166. _stprintf_s(pic_extension, EXTENCTION_LEN, __T("ppm"));
  167. break;
  168. default:
  169. exit(-1);
  170. break;
  171. }
  172. break;
  173. case S_PNG:
  174. _stprintf_s(pic_extension, EXTENCTION_LEN, __T("png"));
  175. break;
  176. case S_JPG:
  177. _stprintf_s(pic_extension, EXTENCTION_LEN, __T("jpg"));
  178. break;
  179. default:
  180. exit(-1);
  181. break;
  182. }
  183. while (1){//ファイル名重複対策
  184. i++;
  185. GetCurrentDirectory(MAX_PATH + 1, crDir);
  186. PathAddBackslash(crDir);
  187. TCHAR temp[FILE_NAME_SUB_LEN + 1];
  188. _stprintf_s(tfilename, _tcslen(tfilename) + 1, __T("%s"), tcore_filename);
  189. _stprintf_s(temp, FILE_NAME_SUB_LEN + 1, __T("%d_%02d.%s"), roop_turn, i, pic_extension);
  190. _tcscat_s(tfilename, _tcslen(tfilename) + FILE_NAME_SUB_LEN + 1, temp);
  191. _tcscat_s(crDir, MAX_PATH + _tcslen(tfilename) + FILE_NAME_SUB_LEN + 1, tfilename);
  192. if (PathFileExists(crDir) == 0) break;
  193. }
  194. return 0;
  195. }
  196. void DrawCursor(HDC hdc)
  197. {
  198. int x, y;
  199. CURSORINFO cursorInfo;
  200. ICONINFO iconInfo;
  201.  
  202. cursorInfo.cbSize = sizeof(CURSORINFO);
  203. GetCursorInfo(&cursorInfo);
  204.  
  205. GetIconInfo(cursorInfo.hCursor, &iconInfo);
  206.  
  207. x = cursorInfo.ptScreenPos.x - iconInfo.xHotspot;
  208. y = cursorInfo.ptScreenPos.y - iconInfo.yHotspot;
  209. DrawIcon(hdc, x, y, cursorInfo.hCursor);
  210. }
  211. bool WriteBitmap(LPTSTR lpszFileName, LPVOID lpBits, BITMAPINFOHEADER *bmiHeader)
  212. {
  213. HANDLE hFile;
  214. DWORD dwResult;
  215. BITMAPFILEHEADER bmfHeader;
  216.  
  217. hFile = CreateFile(lpszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);//カレントディレクトリにファイル作成
  218. if (hFile == INVALID_HANDLE_VALUE)
  219. return false;
  220.  
  221. ZeroMemory(&bmfHeader, sizeof(BITMAPFILEHEADER));
  222. bmfHeader.bfType = *(LPWORD)"BM";
  223. bmfHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + bmiHeader->biSizeImage;
  224. bmfHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
  225.  
  226. WriteFile(hFile, &bmfHeader, sizeof(BITMAPFILEHEADER), &dwResult, NULL);
  227. WriteFile(hFile, bmiHeader, sizeof(BITMAPINFOHEADER), &dwResult, NULL);
  228. WriteFile(hFile, lpBits, bmiHeader->biSizeImage, &dwResult, NULL);
  229.  
  230. CloseHandle(hFile);
  231.  
  232. return true;
  233. }
  234. int Command_line_Analyzer(const int argc, char *argv[], PROCESS_CONF *pre_config){
  235. if (argc == 1){
  236. pre_config->pic_type = S_JPG;
  237. pre_config->frame_num = 1;
  238. pre_config->use_param = false;
  239. pre_config->process_mode = 0;
  240. return 0;
  241. }
  242. int return_num = 0;
  243. if (strcmp(argv[1], "-h") == 0) print_help();
  244. if (argc < 4 * 2 + 1) print_command_line_error(1);
  245. int i;
  246. for (i = 1; i < argc; i++){
  247. if (0 == strcmp(argv[i], "-f")){
  248. const unsigned int temp = sgetnum(argv[i + 1], UINT_MAX, 0);
  249. if (temp == -1)
  250. pre_config->frame_num = 1;// print_command_line_error(2);
  251. else
  252. pre_config->frame_num = temp;
  253. i++;
  254. }
  255. if (0 == strcmp(argv[i], "-fps")){
  256. const double temp = sgetnum_d(argv[i + 1], FPS_LIMITS, 0);
  257. if (temp == -1) print_command_line_error(3);
  258. if (temp == 23.97)
  259. pre_config->frame_rate = (double)24000 / 1001;
  260. else if (temp == 29.97)
  261. pre_config->frame_rate = (double)30000 / 1001;
  262. else if (temp == 59.94)
  263. pre_config->frame_rate = (double)60000 / 1001;
  264. else
  265. pre_config->frame_rate = temp;
  266. i++;
  267. }
  268. if (0 == strcmp(argv[i], "-p")){//bmp, ppm, pgm, pbn, png, jpg
  269. if (0 == strcmp(argv[i + 1], "bmp"))
  270. pre_config->pic_type = S_BITMAP;
  271. else if (0 == strcmp(argv[i + 1], "png"))
  272. pre_config->pic_type = S_PNG;
  273. else if (0 == strcmp(argv[i + 1], "jpg"))
  274. pre_config->pic_type = S_JPG;
  275. else if (argv[i + 1][0] == 'p' && argv[i + 1][2] == 'm' && (argv[i + 1][1] == 'p' || argv[i + 1][1] == 'g' || argv[i + 1][1] == 'b')){
  276. pre_config->pic_type = S_PXM;
  277. switch (argv[i + 1][1])
  278. {
  279. case 'g':
  280. pre_config->ppm_magic = 5;//P5
  281. pre_config->process_mode = GRAY_SCALED;
  282. break;
  283. case 'b':
  284. pre_config->ppm_magic = 4;//P4
  285. pre_config->process_mode = THRESHOLDING;
  286. break;
  287. default:
  288. pre_config->ppm_magic = 6;//P6
  289. break;
  290. }
  291. }else
  292. print_command_line_error(4);
  293. i++;
  294. }
  295. if (pre_config->process_mode == 0 && 0 == strcmp(argv[i], "-edit")){
  296. const int temp = sgetnum(argv[i + 1], 2, 0);
  297. if (temp < 1)
  298. pre_config->process_mode = 0;
  299. else
  300. pre_config->process_mode = temp;
  301. i++;
  302. }
  303. if (0 == strcmp(argv[i], "-enable-ad-conf")) break;
  304. }
  305. for (; i < argc; i++){
  306. if (0 == strcmp(argv[i], "-b")){
  307. const int temp = sgetnum(argv[i + 1], 1, 0);
  308. if (temp == -1) print_command_line_error(5);
  309. if (temp == 0) pre_config->ppm_magic -= 3;//P1~P3
  310. pre_config->param.pxm_binary[1] = temp;
  311. i++;
  312. }
  313. if (0 == strcmp(argv[i], "-c")){
  314. const int temp = sgetnum(argv[i + 1], 9, 0);
  315. if (temp == -1) print_command_line_error(6);
  316. pre_config->param.png_compression[1] = temp;
  317. i++;
  318. }
  319. if (0 == strcmp(argv[i], "-q")){
  320. const int temp = sgetnum(argv[i + 1], 100, 0);
  321. if (temp == -1) print_command_line_error(7);
  322. pre_config->param.jpeg_quality[1] = temp;
  323. i++;
  324. }
  325. if (0 == strcmp(argv[i], "-n")){
  326. if (argv[i + 1][0] == '-') print_command_line_error(8);
  327. int temp = strlen(argv[i + 1]);
  328. for (int k = 0; k < temp;k++)
  329. if (argv[i + 1][i] == '\\') print_command_line_error(9);
  330. return_num = temp;
  331. i++;
  332. }
  333. if (0 == strcmp(argv[i], "-th")){
  334. const double temp = sgetnum_d(argv[i + 1], 255, 0);
  335. if (temp == -1) print_command_line_error(10);
  336. pre_config->threshold = temp;
  337. i++;
  338. }
  339. }
  340. return 0;
  341. }
  342. int main(int argc, char *argv[])
  343. {
  344. if (argc < 1) exit(1);
  345. timeBeginPeriod(1);// タイマーの最小精度を1msecにする
  346. clock_t first_time = clock();
  347. PROCESS_CONF pre_config = { { { CV_IMWRITE_JPEG_QUALITY, 95 }, { CV_IMWRITE_PNG_COMPRESSION, 3 }, { CV_IMWRITE_PXM_BINARY, 1 } }, false, 0, 6, 0 };
  348. const int core_filename_num = Command_line_Analyzer(argc, argv, &pre_config);//コマンドライン引数解析
  349. const double frame_rate = pre_config.frame_rate;
  350. const unsigned int frame_num = pre_config.frame_num;
  351. /*HWND hwndDesk;
  352. RECT rc;
  353. HDC hdc, hMemDC;
  354. BITMAPINFO bmi;
  355. BITMAP bm;//この中にBITMAPINFOHEADERがある
  356. HBITMAP hBitmap;
  357. LPDWORD lpPixel;
  358. int width, height;
  359. hwndDesk = GetDesktopWindow(); //デスクトップウィンドウのハンドルを取得します
  360. GetWindowRect(hwndDesk, &rc);//指定されたウィンドウの左上端と右下端の座標をスクリーン座標で取得
  361. width = rc.right;
  362. height = rc.bottom;
  363. ZeroMemory(&bmiHeader, sizeof(BITMAPINFOHEADER));
  364. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);//構造体が必要とするバイト数
  365. bmi.bmiHeader.biWidth = rc.right;
  366. bmi.bmiHeader.biHeight = rc.bottom;
  367. bmi.bmiHeader.biPlanes = 1;//ターゲット デバイスに対する面の数を指定する。これは必ず 1
  368.  
  369. bmi.bmiHeader.biBitCount = 32;//1ピクセル当たりのビッット数
  370. //bmi.bmiHeader.biBitCount = 24;
  371.  
  372. bmi.bmiHeader.biCompression = BI_RGB;//非圧縮 RGB
  373. bmi.bmiHeader.biSizeImage = dwSizeImage;
  374. bmi.bmiHeader.biSizeImage = 0;
  375. bmi.bmiHeader.biXPelsPerMeter = 0;
  376. bmi.bmiHeader.biYPelsPerMeter = 0;
  377. bmi.bmiHeader.biClrUsed = 0;
  378. bmi.bmiHeader.biClrImportant = 0;
  379. hdc = GetDC(hwndDesk);//デスクトップウィンドウのデバイスコンテキストを取得
  380. //デバイス独立のビットマップ(DIB)を作成
  381. //デスクトップの解像度がこんだけだからメモリこんだけ用意するとか
  382. //圧縮されてんのかとか 1ピクセルあたりのビト数とかBITMAPINFOにいれてそれを渡す
  383. hBitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&lpPixel, NULL, 0);
  384. hMemDC = CreateCompatibleDC(hdc);//メモリデバイスコンテキストを作成
  385. SelectObject(hMemDC, hBitmap);//ブラシとかそういうのみたいに選択する
  386. BitBlt(hMemDC, 0, 0, width, height, hdc, 0, 0, SRCCOPY);//ビットブロック転送
  387. ReleaseDC(hwndDesk, hdc);//デスクトップウィンドウのデバイスコンテキスト解放
  388. // ビットマップ情報の取得
  389. GetObject(hBitmap, sizeof(BITMAP), &bm);*/
  390. //出力ファイル名決定
  391. char* default_core_filenameA = "caputure";
  392. char* core_filenameA;
  393. if (core_filename_num == 0)
  394. core_filenameA = default_core_filenameA;
  395. else
  396. core_filenameA = argv[core_filename_num];
  397. #ifdef UNICODE
  398. const size_t cchBufW = strlen(core_filenameA) + 1;
  399. //wchar_t* const core_filenameT = new wchar_t[cchBufW * sizeof *core_filenameT];
  400. wchar_t* const core_filenameT = static_cast<wchar_t*>(_alloca(cchBufW * sizeof *core_filenameT));
  401. charToWchart(core_filenameA, core_filenameT, cchBufW);
  402. #else
  403. #define core_filenameT core_filenameA
  404. #endif
  405. //for
  406. #ifdef UNICODE
  407. wchar_t* const tFilename = new wchar_t[(cchBufW + FILE_NAME_SUB_LEN + 1) * sizeof *tFilename];
  408. //wchar_t* const tFilename = static_cast<wchar_t*>(_alloca((cchBufW + FILE_NAME_SUB_LEN) * sizeof *tFilename));
  409. #else
  410. char* const tFilename = new char[((strlen(argv[core_filename_num]) + FILE_NAME_SUB_LEN + 2) * sizeof *tFilename];
  411. //char* const tFilename = static_cast<char*>(_alloca((strlen(argv[core_filename_num]) + 1 + FILE_NAME_SUB_LEN) * sizeof *tFilename));
  412. #endif
  413. Determine_Filename(1, tFilename, core_filenameT, pre_config.pic_type);
  414. #ifdef UNICODE
  415. const size_t cchBufA = wcslen(tFilename) + 1;
  416. char *aFilename = new char[cchBufA * sizeof *aFilename];
  417. //char *aFilename = static_cast<char*>(_alloca(cchBufA * sizeof *aFilename));
  418. wchartToChar(tFilename, aFilename, cchBufA);
  419. #else
  420. #define aFilename tFilename
  421. #endif
  422.  
  423. HDC hdc;
  424. HWND hwndDesk;
  425. RECT rc;
  426. BITMAP bm;
  427. LPVOID lpPixel;
  428. BITMAPINFO bmi;
  429. HBITMAP hbmp;
  430. HBITMAP hbmpPrev;
  431. BITMAPINFOHEADER bmiHeader;
  432. hwndDesk = GetDesktopWindow();//DesktopのWindowHandle
  433.  
  434. GetWindowRect(hwndDesk, &rc);
  435.  
  436. DWORD dwSizeImage = rc.bottom * ((3 * rc.right + 3) / 4) * 4;
  437. ZeroMemory(&bmiHeader, sizeof(BITMAPINFOHEADER));
  438. bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  439. bmiHeader.biWidth = rc.right;
  440. bmiHeader.biHeight = rc.bottom;
  441. bmiHeader.biPlanes = 1;
  442. if (pre_config.pic_type == S_BITMAP && pre_config.process_mode == 0)//OpenCVには32、WriteBitmapには24
  443. bmiHeader.biBitCount = 24;
  444. else
  445. bmiHeader.biBitCount = 32;
  446. bmiHeader.biCompression = BI_RGB;
  447. bmiHeader.biSizeImage = dwSizeImage;
  448. bmiHeader.biXPelsPerMeter = 0;
  449. bmiHeader.biYPelsPerMeter = 0;
  450. bmiHeader.biClrUsed = 0;
  451. bmiHeader.biClrImportant = 0;
  452. bmi.bmiHeader = bmiHeader;
  453. hdc = CreateCompatibleDC(NULL);
  454. hbmp = CreateDIBSection(NULL, (LPBITMAPINFO)&bmi, DIB_RGB_COLORS, &lpPixel, NULL, 0);;
  455. hbmpPrev = (HBITMAP)SelectObject(hdc, hbmp);
  456.  
  457. BitBlt(hdc, 0, 0, rc.right, rc.bottom, GetWindowDC(hwndDesk), 0, 0, SRCCOPY);//これがキャプチャー部分
  458. //GetWindowDCの制約によりWindwos2000以前ではマルチモニター環境ではプライマリモニタ以外に対象があると失敗する
  459. DrawCursor(hdc);
  460.  
  461. GetObject(hbmp, sizeof(BITMAP), &bm);
  462. if (pre_config.pic_type != S_BITMAP || pre_config.process_mode != 0){//ただのBITMAPで編集しないならOpenCVは使わず、else文へ
  463. IplImage *convertIplImg, *convertIplImg1, *convertIplImg2;
  464. convertIplImg = cvCreateImage(cvSize(bmiHeader.biWidth, bmiHeader.biHeight), IPL_DEPTH_8U, 4);//メモリ確保
  465. convertIplImg1 = cvCreateImage(cvSize(bmiHeader.biWidth, bmiHeader.biHeight), IPL_DEPTH_8U, 4);//メモリ確保
  466. //ビットマップを構成する各ピクセルの色は、
  467. //ビットイメージ(またはピクセルビット)と呼ばれる配列に格納されています。
  468. //よって、この配列にアクセスすれば、
  469. //ビットマップの任意の位置の色を取得することができます。
  470. //ビットイメージは、BITMAP構造体のbmBits
  471. memcpy(convertIplImg->imageData, bm.bmBits, bmiHeader.biWidth * bmiHeader.biHeight * 4);
  472. cvFlip(convertIplImg, convertIplImg1, 0);//水平軸反転
  473. if (pre_config.process_mode == THRESHOLDING){
  474. convertIplImg2 = cvCreateImage(cvGetSize(convertIplImg1), IPL_DEPTH_8U, 1);
  475. cvSmooth(convertIplImg1, convertIplImg1, CV_GAUSSIAN, 5);
  476. if (pre_config.threshold != 0)
  477. cvThreshold(convertIplImg1, convertIplImg2, pre_config.threshold, 255, CV_THRESH_BINARY);
  478. else
  479. cvThreshold(convertIplImg1, convertIplImg2, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);// (1)二値化(大津の手法を利用)
  480. if (pre_config.use_param){
  481. switch (pre_config.pic_type)
  482. {
  483. case S_PXM:
  484. if (pre_config.param.pxm_binary[1] == 1)
  485. cvSaveImage(aFilename, convertIplImg2, pre_config.param.pxm_binary);
  486. else
  487. cvSaveImage(aFilename, convertIplImg2, 0);
  488. break;
  489. case S_PNG:
  490. if (pre_config.param.png_compression[1] != 3)
  491. cvSaveImage(aFilename, convertIplImg2, pre_config.param.png_compression);
  492. else
  493. cvSaveImage(aFilename, convertIplImg2, 0);
  494. break;
  495. case S_JPG:
  496. if (pre_config.param.jpeg_quality[1] != 95)
  497. cvSaveImage(aFilename, convertIplImg2, pre_config.param.jpeg_quality);
  498. else
  499. cvSaveImage(aFilename, convertIplImg2, 0);
  500. default:
  501. cvSaveImage(aFilename, convertIplImg2, 0);
  502. break;
  503. }
  504. }
  505. else{
  506. cvSaveImage(aFilename, convertIplImg2, 0);
  507. }
  508. cvReleaseImage(&convertIplImg2);
  509. }
  510. else if (pre_config.process_mode == GRAY_SCALED){
  511. convertIplImg2 = cvCreateImage(cvGetSize(convertIplImg1), IPL_DEPTH_8U, 1);
  512. cvCvtColor(convertIplImg1, convertIplImg2, CV_BGR2GRAY);
  513. cvSaveImage(aFilename, convertIplImg2, 0);
  514. cvReleaseImage(&convertIplImg2);
  515. }
  516. else{
  517. cvSaveImage(aFilename, convertIplImg1, 0);
  518. }
  519. // 終了処理
  520. cvReleaseImage(&convertIplImg);
  521. cvReleaseImage(&convertIplImg1);
  522. }
  523. else{
  524. if ((WriteBitmap(tFilename, bm.bmBits, &bmiHeader)) == false)
  525. return -1;
  526. }
  527. // 終了処理
  528. //SelectObject(hdc, hbmpPrev);//これ何なのかよくわからない
  529. //cf.)http://e...content-available-to-author-only...s.jp/graphics/bitmap/bitmap16.html
  530. DeleteObject(hbmp);
  531. DeleteDC(hdc);
  532. delete[] tFilename;
  533. #ifdef UNICODE
  534. delete[] aFilename;
  535. #endif
  536. clock_t finish_time = clock();
  537. timeEndPeriod(1);// タイマーの最小精度を戻す
  538. printf("Finish process.");
  539. printf("\n%lf[sec.](%d)\n", (double)(finish_time - first_time) / CLOCKS_PER_SEC, finish_time - first_time);
  540. return 0;
  541. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:99: fatal error: opencv2/core/core.hpp: No such file or directory
 #include <opencv2/core/core.hpp>        // coreモジュールのヘッダーをインクルード
                                                                                                   ^
compilation terminated.
stdout
Standard output is empty