// FaceRec9.cpp : Defines the entry point for the application. // #include "framework.h" #include "omp.h" #include "math.h" #include "fftw3.h" #include "new.h" #include #include #include #include #include "opencv2/imgcodecs/imgcodecs.hpp" #include #include #include #include "GetFreq_REC.h" #include "FaceRec9.h" using namespace cv; using namespace std; typedef unsigned char byte; #define MAX_LOADSTRING 100 byte* bytes, * bytes1, * bytes3, * bytesX; char POM[200], POM1[200], POM2[200]; int selClan; int N1 = 768, N2 = 1366, N = 768; int PROLAZ, PROLAZ1, pprolaz, povrat = 0, KAMERA = 1; int brUz, brUzObj; int brObjects = 7, brFreq = 1014; // brFreq_REC = 338*3 (RGB) int poz, poz1, cancel; LRESULT checkBoxes[2]; int XX, YY; static HWND hwndButton; double largest, largest1; double S_R[768][1366], S_G[768][1366], S_B[768][1366]; double** largX; double** A_R, ** A_G, ** A_B; double*** R_REC; GetFreq_REC** REC; char** names; FILE* stream; VideoCapture cap; // ********************************************************************************** // ***** Get Image functions **************************************************** // ********************************************************************************** // ***** Recognition function *************************************** void GetImage_FACEREC(HWND hWnd) { namedWindow("FaceRecognition", WINDOW_NORMAL); setWindowProperty("FaceRecognition", WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN); int i, j; Mat frame = Mat(768, 1366, CV_8UC3); while (1) { Mat temp; bool bSuccess = cap.read(temp); // read new frame from video if (!bSuccess) // if not success, break loop { destroyAllWindows(); MessageBox(hWnd, TEXT("Frame not captured !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; } // *** cut frame from large temp image { Rect ROI(469, 264, 1366, 768); // temp image: 1296x2304 pix temp(ROI).copyTo(frame); // frame image: 768x1366 pix } // *** put it to the buffer for processing in recognition subroutine std::memcpy(bytes, frame.data, 3147264 * sizeof(byte)); // *** draw 768x768 pix rectangle in the frame rectangle(frame, Point(299, 0), Point(1067, 768), Scalar(63, 191, 127, 255), 11, LINE_AA, 0); int R = 0; int G = 255; int B = 0; // *** draw circles arround eyes RotatedRect rRect = RotatedRect(Point2f(491, 216), Size2f(192, 192), 0); // 491 ellipse(frame, rRect, Scalar(B, G, R, 255), 1, LINE_AA); rRect = RotatedRect(Point2f(491, 216), Size2f(96, 96), 0); ellipse(frame, rRect, Scalar(B, G, R, 255), 1, LINE_AA); rRect = RotatedRect(Point2f(875, 216), Size2f(192, 192), 0); // 875 ellipse(frame, rRect, Scalar(B, G, R, 255), 1, LINE_AA); rRect = RotatedRect(Point2f(875, 216), Size2f(96, 96), 0); ellipse(frame, rRect, Scalar(B, G, R, 255), 1, LINE_AA); if (largest > 0.5) { rectangle(frame, Point(18, 458), Point(118, 558), Scalar(127, 127, 127, 255), FILLED, LINE_AA, 0); Mat frame_REC = Mat(96, 96, CV_8UC3, bytes1).clone(); { Rect ROI(20, 460, 96, 96); frame_REC.copyTo(frame(ROI)); } } if (largest > 0.5) { G = 0; R = 255; } // *** draw circles with changed colours rRect = RotatedRect(Point2f(491, 216), Size2f(192, 192), 0); // 491 ellipse(frame, rRect, Scalar(B, G, R, 255), 1, LINE_AA); rRect = RotatedRect(Point2f(491, 216), Size2f(13, 13), 0); ellipse(frame, rRect, Scalar(B, G, R, 255), FILLED, LINE_AA); rRect = RotatedRect(Point2f(875, 216), Size2f(192, 192), 0); // 875 ellipse(frame, rRect, Scalar(B, G, R, 255), 1, LINE_AA); rRect = RotatedRect(Point2f(875, 216), Size2f(13, 13), 0); ellipse(frame, rRect, Scalar(B, G, R, 255), FILLED, LINE_AA); // *** draw names and probabilities for detected face i = poz / brUzObj; sprintf_s(POM, 200, "%s", names[i]); j = 640 - ((int)strlen(names[i]) / 2 * 40) + 20; if (largest > 0.5) putText(frame, POM, Point2f((float)j, 100), FONT_HERSHEY_TRIPLEX, 2, Scalar(0, 0, 255, 255), 1, LINE_AA, false); else putText(frame, POM, Point2f((float)j, 100), FONT_HERSHEY_TRIPLEX, 2, Scalar(255, 0, 0, 255), 1, LINE_AA, false); sprintf_s(POM, 200, "imageNr = %d", poz + 1); if (largest > 0.5) putText(frame, POM, Point2f(430, 680), FONT_HERSHEY_COMPLEX_SMALL, 1, Scalar(0, 0, 255, 255), 1, LINE_AA, false); else putText(frame, POM, Point2f(430, 680), FONT_HERSHEY_COMPLEX_SMALL, 1, Scalar(255, 0, 0, 255), 1, LINE_AA, false); sprintf_s(POM, 200, "prob = %.5f", largest); if (largest > 0.5) putText(frame, POM, Point2f(430, 700), FONT_HERSHEY_COMPLEX_SMALL, 1, Scalar(0, 0, 255, 255), 1, LINE_AA, false); else putText(frame, POM, Point2f(430, 700), FONT_HERSHEY_COMPLEX_SMALL, 1, Scalar(255, 0, 0, 255), 1, LINE_AA, false); imshow("FaceRecognition", frame); if ((waitKey(1) == 27) || (KAMERA == 1)) //wait for 'esc' key press for 1ms. If 'esc' key is pressed, break loop { destroyAllWindows(); break; } } KAMERA = 1; } // ***** Recognition with Face Detection ******************* void GetImage_FACEDET_REC(HWND hWnd) { int i, j; namedWindow("FaceDetRec", WINDOW_NORMAL); moveWindow("FaceDetRec", XX, YY); setWindowProperty("FaceDetRec", WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN); Mat frame = Mat(768, 1366, CV_8UC3); while (1) { Mat temp; bool bSuccess = cap.read(temp); // read new frame from video if (!bSuccess) //if not success, break loop { destroyAllWindows(); MessageBox(hWnd, TEXT("Frame not captured !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; } // *** cut 768x1366 pix frame from 2304x1296 pix video image { Rect ROI(469, 264, 1366, 768); // temp image: (2304, 1296) temp(ROI).copyTo(frame); } // *** buffer it std::memcpy(bytes, frame.data, 3147264 * sizeof(byte)); // *** draw rectangles rectangle(frame, Point(299, 0), Point(1067, 768), Scalar(63, 127, 191, 255), 11, LINE_AA, 0); // *** if above threashold show image from detection process if (largest > 0.2) { rectangle(frame, Point(48, 248), Point(104, 304), Scalar(127, 127, 127, 255), FILLED, LINE_AA, 0); Mat frame_REC = Mat(52, 52, CV_8UC3, bytes1).clone(); { Rect ROI(50, 250, 52, 52); frame_REC.copyTo(frame(ROI)); } Mat frame1_REC = Mat(96, 96, CV_8UC3, bytes3).clone(); rectangle(frame, Point(118, 443), Point(218, 543), Scalar(127, 127, 127, 255), FILLED, LINE_AA, 0); { Rect ROI(120, 445, 96, 96); frame1_REC.copyTo(frame(ROI)); } putText(frame, "DB Image:", Point2f(120, 435), FONT_HERSHEY_PLAIN, 1, Scalar(255, 0, 0, 255), 1, LINE_AA, false); } // *** if above threashold show image from recognition process if (largest1 > 0.5) { Mat frame1_REC = Mat(96, 96, CV_8UC3, bytes3).clone(); rectangle(frame, Point(118, 443), Point(218, 543), Scalar(127, 127, 127, 255), FILLED, LINE_AA, 0); { Rect ROI(120, 445, 96, 96); frame1_REC.copyTo(frame(ROI)); } putText(frame, "DB Image:", Point2f(120, 435), FONT_HERSHEY_PLAIN, 1, Scalar(0, 0, 255, 255), 1, LINE_AA, false); } // *** detection pass nr. counter sprintf_s(POM, 200, "Pass: %d", PROLAZ); putText(frame, POM, Point2f(20, 150), FONT_HERSHEY_PLAIN, 1.5, Scalar(0, 0, 255, 255), 1, LINE_AA, false); sprintf_s(POM, 200, "PassLocal: %d", PROLAZ1); putText(frame, POM, Point2f(50, 220), FONT_HERSHEY_PLAIN, 1, Scalar(0, 0, 255, 255), 1, LINE_AA, false); // *** display name, probability and image nr. of recognized face i = poz1 / brUzObj; sprintf_s(POM, 200, "%s", names[i]); j = 640 - ((int)strlen(names[i]) / 2 * 40) + 20; if (largest1 > 0.5) putText(frame, POM, Point2f((float)j, 100), FONT_HERSHEY_TRIPLEX, 2, Scalar(0, 0, 255, 255), 1, LINE_AA, false); else putText(frame, POM, Point2f((float)j, 100), FONT_HERSHEY_TRIPLEX, 2, Scalar(255, 0, 0, 255), 1, LINE_AA, false); sprintf_s(POM, 200, "Face pattern image:"); putText(frame, POM, Point2f(20, 190), FONT_HERSHEY_PLAIN, 1, Scalar(0, 0, 255, 255), 1, LINE_AA, false); sprintf_s(POM, 200, "imageNr = %d", poz1 + 1); if (largest1 > 0.5) putText(frame, POM, Point2f(530, 680), FONT_HERSHEY_COMPLEX_SMALL, 1, Scalar(0, 0, 255, 255), 1, LINE_AA, false); else putText(frame, POM, Point2f(530, 680), FONT_HERSHEY_COMPLEX_SMALL, 1, Scalar(255, 0, 0, 255), 1, LINE_AA, false); sprintf_s(POM, 200, "prob = %.5f", largest1); if (largest1 > 0.5) putText(frame, POM, Point2f(530, 700), FONT_HERSHEY_COMPLEX_SMALL, 1, Scalar(0, 0, 255, 255), 1, LINE_AA, false); else putText(frame, POM, Point2f(530, 700), FONT_HERSHEY_COMPLEX_SMALL, 1, Scalar(255, 0, 0, 255), 1, LINE_AA, false); imshow("FaceDetRec", frame); if ((waitKey(1) == 27) || (KAMERA == 1)) //wait for 'esc' key press for 1ms. If 'esc' key is pressed, break loop { destroyAllWindows(); break; } } KAMERA = 1; } // ***** Database Creation ***** void GetImage_RecogDB(HWND hWnd) { namedWindow("RecognitionDB", WINDOW_NORMAL); setWindowProperty("RecognitionDB", WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN); int R = 0; int G = 0; int B = 255; Mat frame = Mat(768, 1366, CV_8UC3); while (1) { Mat temp; bool bSuccess = cap.read(temp); // read a new frame from video if (!bSuccess) //if not success, break loop { destroyAllWindows(); MessageBox(hWnd, TEXT("Frame not captured !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; } { Rect ROI(469, 264, 1366, 768); // temp image: (2304x1296) temp(ROI).copyTo(frame); } std::memcpy(bytes, frame.data, 3147264 * sizeof(byte)); // 1366x768x3 if (PROLAZ == 50) { R = 255; B = 0; } if (PROLAZ == 350) { G = 255; R = 0; } RotatedRect rRect = RotatedRect(Point2f(491, 216), Size2f(192, 192), 0); // 240 ellipse(frame, rRect, Scalar(B, G, R, 255), 1, LINE_AA); rRect = RotatedRect(Point2f(875, 216), Size2f(192, 192), 0); ellipse(frame, rRect, Scalar(B, G, R, 255), 1, LINE_AA); rRect = RotatedRect(Point2f(491, 216), Size2f(15, 15), 0); ellipse(frame, rRect, Scalar(B, G, R, 255), FILLED, LINE_AA); rRect = RotatedRect(Point2f(875, 216), Size2f(15, 15), 0); ellipse(frame, rRect, Scalar(B, G, R, 255), FILLED, LINE_AA); imshow("RecognitionDB", frame); if ((waitKey(1) == 27) || (KAMERA == 1)) //wait for 'esc' key press for 1ms. If 'esc' key is pressed, break loop { destroyAllWindows(); break; } } KAMERA = 1; } // ******************************************** // *** DYNAMIC FIELDS ********************* // ******************************************** int CreateDynamicFields() { char ch; int i, j, k; if (fopen_s(&stream, ".\\brUzoraka.txt", "r") == 0) { i = 0; while ((ch = fgetc(stream)) != ',') POM[i++] = ch; POM[i] = '\0'; brUz = atoi(POM); i = 0; while ((ch = fgetc(stream)) != '#') POM[i++] = ch; POM[i] = '\0'; brUzObj = atoi(POM); fclose(stream); } else return (0); if (fopen_s(&stream, ".\\monitors.dat", "r") == 0) { fread(checkBoxes, sizeof(LRESULT), (2), stream); fclose(stream); if (checkBoxes[1] == BST_CHECKED) { XX = GetSystemMetrics(SM_CXSCREEN); YY = -GetSystemMetrics(SM_CYSCREEN); } else { XX = 0; YY = 0; } } else return (0); REC = new GetFreq_REC * [brObjects]; if (brUz == 0) return (1); R_REC = new double** [brObjects]; for (int i = 0; i < brObjects; i++) { R_REC[i] = new double* [brUz]; for (int j = 0; j < brUz; j++) R_REC[i][j] = new double[brFreq]; } largX = new double* [brObjects]; for (i = 0; i < brObjects; i++) largX[i] = new double[brUz]; names = new char* [brUz / brUzObj]; if ((fopen_s(&stream, ".\\names.txt", "r") == 0) && (stream != NULL)) { j = 0; ch = '$'; while (ch != '#') { i = 0; while (((ch = fgetc(stream)) != '\n') && (ch != '#')) { POM[i++] = ch; } POM[i++] = '\0'; if (ch == '#') break; names[j] = new char[i]; for (k = 0; k < i; k++) names[j][k] = POM[k]; j++; } fclose(stream); } else return(0); return(1); } void DestroyDynamicFields() { int i, j; if (brUz == 0) { delete[] REC; return; } for (i = 0; i < brUz / brUzObj; i++) delete[] names[i]; delete[] names; for (i = 0; i < brObjects; i++) { for (j = 0; j < brUz; j++) delete[] R_REC[i][j]; delete[] R_REC[i]; } delete[] R_REC; for (i = 0; i < brObjects; i++) delete[] largX[i]; delete[] largX; delete[] REC; } int SpremiPodatke(int SW) { int i; if ((fopen_s(&stream, ".\\brUzoraka.txt", "w+t") == 0) && (stream != NULL)) { fprintf_s(stream, "%d,%d#", brUz, brUzObj); fclose(stream); } else return(0); if ((fopen_s(&stream, ".\\names.txt", "w+t") == 0) && (stream != NULL)) { if (SW == 0) { for (i = 0; i < (brUz - brUzObj) / brUzObj; i++) fprintf_s(stream, "%s\n", names[i]); fprintf_s(stream, "%d. %s\n", i + 1, POM); } else { for (i = 0; i < (brUz) / brUzObj; i++) fprintf_s(stream, "%s\n", names[i]); } fprintf_s(stream, "#"); fclose(stream); } else return(0); return(1); } // *************************************************** // *** reduce x time x image to y time y image *** // *************************************************** void Reduce_Image_FFTW(int x, int y) { int i, j; double* x_R = (double*)fftw_malloc(sizeof(double) * (size_t)x * (size_t)x); for (i = 0; i < x; i++) for (j = 0; j < x; j++) x_R[i * x + j] = S_R[i][j]; fftw_complex* y_R = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * (size_t)x * ((size_t)x / 2 + 1)); fftw_plan plan_R = fftw_plan_dft_r2c_2d(x, x, x_R, y_R, FFTW_ESTIMATE); double* x_G = (double*)fftw_malloc(sizeof(double) * x * x); for (i = 0; i < x; i++) for (j = 0; j < x; j++) x_G[i * x + j] = S_G[i][j]; fftw_complex* y_G = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * (size_t)x * ((size_t)x / 2 + 1)); fftw_plan plan_G = fftw_plan_dft_r2c_2d(x, x, x_G, y_G, FFTW_ESTIMATE); double* x_B = (double*)fftw_malloc(sizeof(double) * (size_t)x * (size_t)x); for (i = 0; i < x; i++) for (j = 0; j < x; j++) x_B[i * x + j] = S_B[i][j]; fftw_complex* y_B = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * (size_t)x * ((size_t)x / 2 + 1)); fftw_plan plan_B = fftw_plan_dft_r2c_2d(x, x, x_B, y_B, FFTW_ESTIMATE); fftw_execute(plan_R); fftw_execute(plan_G); fftw_execute(plan_B); for (i = 0; i < y / 2; i++) for (j = 0; j < y / 2; j++) { y_R[i * (y / 2 + 1) + j][0] = y_R[i * (x / 2 + 1) + j][0]; y_R[i * (y / 2 + 1) + j][1] = y_R[i * (x / 2 + 1) + j][1]; y_G[i * (y / 2 + 1) + j][0] = y_G[i * (x / 2 + 1) + j][0]; y_G[i * (y / 2 + 1) + j][1] = y_G[i * (x / 2 + 1) + j][1]; y_B[i * (y / 2 + 1) + j][0] = y_B[i * (x / 2 + 1) + j][0]; y_B[i * (y / 2 + 1) + j][1] = y_B[i * (x / 2 + 1) + j][1]; } for (i = y / 2; i < y; i++) for (j = 0; j < y / 2; j++) { y_R[i * (y / 2 + 1) + j][0] = y_R[(i + (x - y)) * (x / 2 + 1) + j][0]; y_R[i * (y / 2 + 1) + j][1] = y_R[(i + (x - y)) * (x / 2 + 1) + j][1]; y_G[i * (y / 2 + 1) + j][0] = y_G[(i + (x - y)) * (x / 2 + 1) + j][0]; y_G[i * (y / 2 + 1) + j][1] = y_G[(i + (x - y)) * (x / 2 + 1) + j][1]; y_B[i * (y / 2 + 1) + j][0] = y_B[(i + (x - y)) * (x / 2 + 1) + j][0]; y_B[i * (y / 2 + 1) + j][1] = y_B[(i + (x - y)) * (x / 2 + 1) + j][1]; } fftw_plan plan1_R = fftw_plan_dft_c2r_2d(y, y, y_R, x_R, FFTW_ESTIMATE); fftw_plan plan1_G = fftw_plan_dft_c2r_2d(y, y, y_G, x_G, FFTW_ESTIMATE); fftw_plan plan1_B = fftw_plan_dft_c2r_2d(y, y, y_B, x_B, FFTW_ESTIMATE); fftw_execute(plan1_R); fftw_execute(plan1_G); fftw_execute(plan1_B); for (i = 0; i < y; i++) for (j = 0; j < y; j++) { S_R[i][j] = x_R[i * y + j] / ((size_t)x * x); if (S_R[i][j] < 0) S_R[i][j] = 0; else if (S_R[i][j] > 255) S_R[i][j] = 255; S_G[i][j] = x_G[i * y + j] / ((size_t)x * x); if (S_G[i][j] < 0) S_G[i][j] = 0; else if (S_G[i][j] > 255) S_G[i][j] = 255; S_B[i][j] = x_B[i * y + j] / ((size_t)x * x); if (S_B[i][j] < 0) S_B[i][j] = 0; else if (S_B[i][j] > 255) S_B[i][j] = 255; } fftw_free(x_R); fftw_free(x_G); fftw_free(x_B); fftw_free(y_R); fftw_free(y_G); fftw_free(y_B); fftw_destroy_plan(plan_R); fftw_destroy_plan(plan_G); fftw_destroy_plan(plan_B); fftw_destroy_plan(plan1_R); fftw_destroy_plan(plan1_G); fftw_destroy_plan(plan1_B); } void GetFaceRegion() { int i, j, k, m, n, p, r, s; double pom, pom1; // *** resize NxN (768x768) pix image to 80x80 pix Reduce_Image_FFTW(N, 80); // ************ // *** 1 *** buffer image (80x80 pix) // ************ for (i = 0; i < 80; i++) for (j = 0; j < 80; j++) { A_B[i][j] = S_B[i][j]; A_G[i][j] = S_G[i][j]; A_R[i][j] = S_R[i][j]; } // *** resize original image to 52x52 pix *** Reduce_Image_FFTW(80, 52); // *** buffer 52x52 pix image for (i = 0; i < 52; i++) for (j = 0; j < 52; j++) { bytesX[(size_t)i * 156 + (size_t)j * 3] = (byte)S_B[i][j]; bytesX[(size_t)i * 156 + (size_t)j * 3 + 1] = (byte)S_G[i][j]; bytesX[(size_t)i * 156 + (size_t)j * 3 + 2] = (byte)S_R[i][j]; } // *** initialize objects k = 0; for (m = 0; m < 14; m += 13) for (n = 0; n < 27; n += 13) { for (p = 0; p < 26; p++) for (r = 0; r < 26; r++) { REC[k]->SX_R[p][r] = S_R[m + p][n + r]; REC[k]->SX_G[p][r] = S_G[m + p][n + r]; REC[k]->SX_B[p][r] = S_B[m + p][n + r]; } k++; } m = 26; n = 13; for (p = 0; p < 26; p++) for (r = 0; r < 26; r++) { REC[k]->SX_R[p][r] = S_R[m + p][n + r]; REC[k]->SX_G[p][r] = S_G[m + p][n + r]; REC[k]->SX_B[p][r] = S_B[m + p][n + r]; } // *** process objects #pragma omp parallel sections num_threads(2) { #pragma omp section { REC[0]->GetFreq(); REC[1]->GetFreq(); REC[2]->GetFreq(); } #pragma omp section { REC[3]->GetFreq(); REC[4]->GetFreq(); REC[5]->GetFreq(); } } REC[6]->GetFreq(); // *** calculate probabilities for (i = 0; i < brUz; i++) { pom = 0; for (j = 0; j < brObjects; j++) pom += largX[j][i]; pom /= brObjects; if (pom > largest) { largest = pom; poz = i; } } // *********** // *** 2 *** cut frames from original image A *** // *********** s = 76; while ((s > 51) && (KAMERA == 0)) { for (m = 0; m < 80 - s; m++) for (n = 0; n < 80 - s; n++) { for (i = m; i < m + s; i++) for (j = n; j < n + s; j++) { S_B[i - m][j - n] = A_B[i][j]; S_G[i - m][j - n] = A_G[i][j]; S_R[i - m][j - n] = A_R[i][j]; } // *** resize to 52x52 pix if (s > 52) Reduce_Image_FFTW(s, 52); k = 0; for (i = 0; i < 14; i += 13) for (j = 0; j < 27; j += 13) { for (p = 0; p < 26; p++) for (r = 0; r < 26; r++) { REC[k]->SX_R[p][r] = S_R[i + p][j + r]; REC[k]->SX_G[p][r] = S_G[i + p][j + r]; REC[k]->SX_B[p][r] = S_B[i + p][j + r]; } k++; } i = 26; j = 13; for (p = 0; p < 26; p++) for (r = 0; r < 26; r++) { REC[k]->SX_R[p][r] = S_R[i + p][j + r]; REC[k]->SX_G[p][r] = S_G[i + p][j + r]; REC[k]->SX_B[p][r] = S_B[i + p][j + r]; } // *** process objects #pragma omp parallel sections num_threads(2) { #pragma omp section { REC[0]->GetFreq(); REC[1]->GetFreq(); REC[2]->GetFreq(); } #pragma omp section { REC[3]->GetFreq(); REC[4]->GetFreq(); REC[5]->GetFreq(); } } REC[6]->GetFreq(); // *** calculate probabilities pom1 = largest; for (i = 0; i < brUz; i++) { pom = 0; for (j = 0; j < brObjects; j++) pom += largX[j][i]; pom /= brObjects; if (pom > largest) { largest = pom; poz = i; } } // *** buffer image if (largest > pom1) { for (i = 0; i < 52; i++) for (j = 0; j < 52; j++) { bytesX[(size_t)i * 156 + (size_t)j * 3] = (byte)S_B[i][j]; bytesX[(size_t)i * 156 + (size_t)j * 3 + 1] = (byte)S_G[i][j]; bytesX[(size_t)i * 156 + (size_t)j * 3 + 2] = (byte)S_R[i][j]; } } } s -= 4; } } void Distances(double** G, int* put) { std::list N, path; std::list::iterator n, m, it, it1; int i; for (i = 0; i < 300; ++i) N.push_back(i); n = N.begin(); path.splice(path.end(), N, n); while (!N.empty()) { it1 = N.begin(); it = path.begin(); for (m = path.begin(); m != path.end(); ++m) { for (n = N.begin(); n != N.end(); ++n) { if (G[*n][*m] > G[*it1][*it]) { it = m; it1 = n; } } } path.splice(path.end(), N, it1); } i = 0; for (n = path.begin(); n != path.end(); ++n) put[i++] = *n; } void RecognizedFace(int rez) { int i, j; sprintf_s(POM1, 200, ".\\MEMBERS\\%d.bmp", rez); byte* bytes5 = new byte[96 * 96 * 3]; Mat frame = imread(POM1, IMREAD_COLOR); if (!frame.empty()) { std::memcpy(bytes5, frame.data, ((size_t)96 * 96 * 3) * sizeof(byte)); for (i = 0; i < 96; i++) for (j = 0; j < 96; j++) { S_B[i][j] = bytes5[i * 288 + j * 3]; S_G[i][j] = bytes5[i * 288 + j * 3 + 1]; S_R[i][j] = bytes5[i * 288 + j * 3 + 2]; } } delete[]bytes5; } void ShowMemberImage(HWND hwnd, int selClan1) { int i, j; sprintf_s(POM, 200, "%s", names[selClan1]); i = 0; while (POM[i] != ' ') i++; j = 0; while (POM[++i] != '\0') POM[j++] = POM[i]; POM[j] = '\0'; sprintf_s(POM1, 200, ".\\MEMBERS\\%s\\%d.bmp", POM, (selClan1 * 300 + 1)); bytes = new byte[96 * 96 * 3]; Mat frame = imread(POM1, IMREAD_COLOR); if (!frame.empty()) { std::memcpy(bytes, frame.data, ((size_t)96 * 96 * 3) * sizeof(byte)); for (i = 0; i < 96; i++) for (j = 0; j < 96; j++) { S_B[i][j] = bytes[i * 288 + j * 3]; S_G[i][j] = bytes[i * 288 + j * 3 + 1]; S_R[i][j] = bytes[i * 288 + j * 3 + 2]; } HDC hdc = GetDC(hwnd); if (selClan1 > -1) { for (i = 0; i < 96; i++) for (j = 0; j < 96; j++) SetPixel(hdc, j + 414, i, RGB((int)(S_R[i][j]), (int)(S_G[i][j]), (int)(S_B[i][j]))); } ReleaseDC(hwnd, hdc); } delete[]bytes; } void ChangeButtonFont(HWND hWnd) { LOGFONT lf; HFONT font; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 48; lf.lfWidth = 12; lstrcpy(lf.lfFaceName, _T("Monotype Corsiva")); font = CreateFontIndirect(&lf); SendMessage(hWnd, WM_SETFONT, (WPARAM)font, TRUE); } // Global Variables: HINSTANCE hInst; // current instance WCHAR szTitle[MAX_LOADSTRING]; // The title bar text WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name // Forward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK UnesiIme(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK PregledClanovaBaze(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK IzbaciClanBaze(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK Create30ElementsDB(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK DBImagesResize(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK CheckBoxes(HWND, UINT, WPARAM, LPARAM); int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: Place code here. // Initialize global strings LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadStringW(hInstance, IDC_FACEREC9, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance(hInstance, nCmdShow)) { return FALSE; } HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_FACEREC9)); MSG msg; // Main message loop: while (GetMessage(&msg, nullptr, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int)msg.wParam; } ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEXW wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_FACEREC9)); wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 3); wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_FACEREC9); wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); return RegisterClassExW(&wcex); } BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { hInst = hInstance; // Store instance handle in our global variable HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, 0, 468 + 16, 90 + 59, nullptr, nullptr, hInstance, nullptr); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int i, j, k, m, n, p, r; double pom; switch (message) { case WM_CREATE: { povrat = CreateDynamicFields(); if ((povrat == 1) && (brUz == 1)) brUz = 0; pprolaz = 1; hwndButton = CreateWindowW(TEXT("button"), TEXT(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_BITMAP | BS_PUSHBUTTON, 310, 17, 140, 60, hWnd, NULL, ((LPCREATESTRUCT)lParam)->hInstance, NULL); // ChangeButtonFont(hwndButton); HANDLE hImg = LoadImage(NULL, L"face.bmp", IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE | LR_LOADFROMFILE); SendMessage(hwndButton, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hImg); // ShowWindow(hwndButton, SW_HIDE); } break; case WM_KILLFOCUS: { if (hwndButton == (HWND)wParam) { SetFocus(hWnd); HDC hdc = GetDC(hWnd); HGDIOBJ penGreen = CreatePen(NULL, 1, RGB(223, 63, 63)); SelectObject(hdc, GetStockObject(NULL_BRUSH)); SelectObject(hdc, penGreen); Rectangle(hdc, 308, 15, 452, 79); ReleaseDC(hWnd, hdc); SendMessage(hWnd, WM_COMMAND, ID_RECOGNITION_RECOGNITIONWITHFACEDETECTION, 1L); } InvalidateRect(hWnd, NULL, TRUE); } break; case WM_COMMAND: { int wmId = LOWORD(wParam); // Parse the menu selections: switch (wmId) { // ************************************************************ // ***** RECOGNITION ********************************** // ************************************************************ case ID_RECOGNITION_RECOGNITION: { if (KAMERA == 0) break; KAMERA = 0; if (brUz == 0) { MessageBox(hWnd, TEXT("Recognition database is empty !"), TEXT("FaceRec9 -> Message:"), MB_OK); KAMERA = 1; break; } cap.open("rtsp://admin:Oknardaj1@192.168.1.11/cam/realmonitor?channel=1&subtype=0"); if (!cap.isOpened()) // if not success, exit program { MessageBox(hWnd, TEXT("Camera not connected !"), TEXT("FaceRec9 -> Message:"), MB_OK); KAMERA = 1; break; } DisableProcessWindowsGhosting(); bytes = new byte[(size_t)N1 * (size_t)N2 * 3](); // buffer for captured image 768x1366 pix RGB bytes1 = new byte[27648](); // 96x96x3 // *** create and initialize recognition object structure for (i = 0; i < brObjects; i++) { REC[i] = new GetFreq_REC(); REC[i]->brUz = brUz; REC[i]->sWitch = 1; REC[i]->largest = largX[i]; REC[i]->R = R_REC[i]; } // *** load recognition DB data for (j = 0; j < brUz; j++) { sprintf_s(POM, 200, ".\\DAT_DB_REC\\%d.dat", j + 1); if (fopen_s(&stream, POM, "r+b") == 0) { for (i = 0; i < brObjects; i++) { fread(R_REC[i][j], sizeof(double), (brFreq), stream); } fclose(stream); } else { MessageBox(hWnd, TEXT("Recognition DB not loaded !"), TEXT("FaceRec9 -> Message:"), MB_OK); goto LAB1; } } omp_set_nested(1); omp_set_dynamic(0); #pragma omp parallel sections shared(bytes, bytes1, largest, poz, KAMERA) num_threads(2) { #pragma omp section { GetImage_FACEREC(hWnd); // image capture function } #pragma omp section { DisableProcessWindowsGhosting(); std::this_thread::sleep_for(std::chrono::milliseconds(200)); // time delay while (KAMERA == 0) { // *** split captured image (768x1366 pix) to RGB components for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { S_B[i][j] = bytes[(size_t)i * ((size_t)N2 * 3) + (size_t)j * 3]; S_G[i][j] = bytes[(size_t)i * ((size_t)N2 * 3) + (size_t)j * 3 + 1]; S_R[i][j] = bytes[(size_t)i * ((size_t)N2 * 3) + (size_t)j * 3 + 2]; } // *** cut 768x768 pix image for each RGB component for (i = 0; i < N; i++) for (j = 0; j < N; j++) S_R[i][j] = S_R[i + (N1 - N) / 2][j + (N2 - N) / 2]; for (i = 0; i < N; i++) for (j = 0; j < N; j++) S_G[i][j] = S_G[i + (N1 - N) / 2][j + (N2 - N) / 2]; for (i = 0; i < N; i++) for (j = 0; j < N; j++) S_B[i][j] = S_B[i + (N1 - N) / 2][j + (N2 - N) / 2]; // *** resize RGB components to 40x40 pix Reduce_Image_FFTW(N, 96); for (i = 0; i < 96; i++) for (j = 0; j < 96; j++) { bytes1[i * 288 + 3 * j] = (byte)S_B[i][j]; bytes1[i * 288 + 3 * j + 1] = (byte)S_G[i][j]; bytes1[i * 288 + 3 * j + 2] = (byte)S_R[i][j]; } Reduce_Image_FFTW(96, 52); // *** load data to object k = 0; for (m = 0; m < 14; m += 13) for (n = 0; n < 27; n += 13) { for (p = 0; p < 26; p++) for (r = 0; r < 26; r++) { REC[k]->SX_R[p][r] = S_R[m + p][n + r]; REC[k]->SX_G[p][r] = S_G[m + p][n + r]; REC[k]->SX_B[p][r] = S_B[m + p][n + r]; } k++; } m = 26; n = 13; for (p = 0; p < 26; p++) for (r = 0; r < 26; r++) { REC[k]->SX_R[p][r] = S_R[m + p][n + r]; REC[k]->SX_G[p][r] = S_G[m + p][n + r]; REC[k]->SX_B[p][r] = S_B[m + p][n + r]; } // *** process objects #pragma omp parallel sections num_threads(2) { #pragma omp section { REC[0]->GetFreq(); REC[1]->GetFreq(); REC[2]->GetFreq(); } #pragma omp section { REC[3]->GetFreq(); REC[4]->GetFreq(); REC[5]->GetFreq(); } } REC[6]->GetFreq(); largest = 0; poz = -1; for (i = 0; i < brUz; i++) { pom = 0; for (j = 0; j < brObjects; j++) pom += largX[j][i]; pom /= brObjects; if (pom > largest) { largest = pom; poz = i; } } } // end while() } // inner pragma } // outer pragma LAB1: KAMERA = 1; delete[] bytes; delete[] bytes1; fftw_cleanup(); cap.release(); } break; // ************************************************************* // ***** RECOGNITION WITH FACEDETECTION ***************** // ************************************************************* case ID_RECOGNITION_RECOGNITIONWITHFACEDETECTION: { if (KAMERA == 0) break; KAMERA = 0; if (brUz == 0) { MessageBox(hWnd, TEXT("Recognition database is empty !"), TEXT("FaceRec9 -> Message:"), MB_OK); KAMERA = 1; break; } cap.open("rtsp://admin:Oknardaj1@192.168.1.11/cam/realmonitor?channel=1&subtype=0"); if (!cap.isOpened()) // if not success, exit program { MessageBox(hWnd, TEXT("Camera not connected !"), TEXT("FaceRec9 -> Message:"), MB_OK); KAMERA = 1; break; } DisableProcessWindowsGhosting(); bytes = new byte[(size_t)N1 * (size_t)N2 * 3](); // image captured from camera (N1 = 768, N2 = 1366) bytes1 = new byte[8112](); // 52x52x3 bytes3 = new byte[27648](); // 96x96x3 A_R = new double* [80]; A_G = new double* [80]; A_B = new double* [80]; for (i = 0; i < 80; i++) { A_R[i] = new double[80](); A_G[i] = new double[80](); A_B[i] = new double[80](); } // *** recognition objects creation and initialization for (i = 0; i < brObjects; i++) { REC[i] = new GetFreq_REC(); // REC[i] = pointer to recognition object program structure REC[i]->brUz = brUz; REC[i]->sWitch = 1; REC[i]->largest = largX[i]; REC[i]->R = R_REC[i]; } // *** load face rec. DB for (j = 0; j < brUz; j++) { sprintf_s(POM, 200, ".\\DAT_DB_REC\\%d.dat", j + 1); if (fopen_s(&stream, POM, "r+b") == 0) { for (i = 0; i < brObjects; i++) { fread(R_REC[i][j], sizeof(double), (brFreq), stream); } fclose(stream); } else { MessageBox(hWnd, TEXT("FaceRecognition DB not loaded !"), TEXT("FaceRec9 -> Message:"), MB_OK); KAMERA = 1; goto LAB2; } } largest1 = largest = 0; poz = poz1 = -1; PROLAZ = 0; omp_set_nested(1); omp_set_dynamic(0); #pragma omp parallel sections shared(bytes, bytes1, bytes3, largest, KAMERA, \ largest1, poz, poz1, PROLAZ, PROLAZ1) num_threads(2) { #pragma omp section { GetImage_FACEDET_REC(hWnd); // image capture function } #pragma omp section { DisableProcessWindowsGhosting(); std::this_thread::sleep_for(std::chrono::milliseconds(200)); // time delay while (KAMERA == 0) { largest1 = largest = 0; poz1 = poz = -1; PROLAZ1 = 0; for (p = 0; p < 52; p++) for (r = 0; r < 52; r++) { bytes1[p * 156 + r * 3] = 0; bytes1[p * 156 + r * 3 + 1] = 0; bytes1[p * 156 + r * 3 + 2] = 0; } for (i = 0; i < 96; i++) for (j = 0; j < 96; j++) { bytes3[i * 288 + j * 3] = 0; bytes3[i * 288 + j * 3 + 1] = 0; bytes3[i * 288 + j * 3 + 2] = 0; } bytesX = new byte[8112]; while ((largest < 0.2) && (KAMERA == 0)) { // *** split captured image to RGB components for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { S_B[i][j] = bytes[(size_t)i * ((size_t)N2 * 3) + (size_t)j * 3]; S_G[i][j] = bytes[(size_t)i * ((size_t)N2 * 3) + (size_t)j * 3 + 1]; S_R[i][j] = bytes[(size_t)i * ((size_t)N2 * 3) + (size_t)j * 3 + 2]; } // *** cut part of the image inside rectangle for each RGB component for (i = 0; i < N; i++) for (j = 0; j < N; j++) S_R[i][j] = S_R[i + (N1 - N) / 2][j + (N2 - N) / 2]; for (i = 0; i < N; i++) for (j = 0; j < N; j++) S_G[i][j] = S_G[i + (N1 - N) / 2][j + (N2 - N) / 2]; for (i = 0; i < N; i++) for (j = 0; j < N; j++) S_B[i][j] = S_B[i + (N1 - N) / 2][j + (N2 - N) / 2]; // *** split image to regions for faster face detection and recognition GetFaceRegion(); PROLAZ1++; } if (KAMERA == 1) { delete[]bytesX; break; } for (i = 0; i < 52; i++) for (j = 0; j < 52; j++) { bytes1[i * 156 + j * 3] = bytesX[i * 156 + j * 3]; bytes1[i * 156 + j * 3 + 1] = bytesX[i * 156 + j * 3 + 1]; bytes1[i * 156 + j * 3 + 2] = bytesX[i * 156 + j * 3 + 2]; } delete[]bytesX; // *** buffer DB image for display largest1 = largest; poz1 = poz; if (poz1 > -1) RecognizedFace(poz + 1); for (i = 0; i < 96; i++) for (j = 0; j < 96; j++) { bytes3[i * 288 + j * 3] = (byte)S_B[i][j]; bytes3[i * 288 + j * 3 + 1] = (byte)S_G[i][j]; bytes3[i * 288 + j * 3 + 2] = (byte)S_R[i][j]; } std::this_thread::sleep_for(std::chrono::milliseconds(6000)); // time delay PROLAZ++; } // end while() } // end pragma inner } // end pragma outer LAB2: for (i = 0; i < 80; i++) { delete[] A_R[i]; delete[] A_G[i]; delete[] A_B[i]; } delete[] A_R; delete[] A_G; delete[] A_B; delete[]bytes3; delete[]bytes1; delete[]bytes; fftw_cleanup(); cap.release(); } break; // ****************************************************************************** // ***** ADD NEW RECOGNITION AND DETECTION DB MEMBER (DISK) ************* // ****************************************************************************** case ID_RECOGNITIONDB_ADDNEWRECOGNITIONDBMEMBER: { if (KAMERA == 0) break; KAMERA = 0; cap.open("rtsp://admin:Oknardaj1@192.168.1.11/cam/realmonitor?channel=1&subtype=0", CAP_ANY); if (!cap.isOpened()) // if not success, exit program { MessageBox(hWnd, TEXT("Camera not connected !"), TEXT("FaceRec9 -> Message:"), MB_OK); KAMERA = 1; break; } DisableProcessWindowsGhosting(); bytes = new byte[(size_t)N1 * (size_t)N2 * 3](); // *** buffer for captured image from camera (N1 = 768, N2 = 1366) // *** initialize recognition and detection objects (Class) for (i = 0; i < brObjects; i++) { REC[i] = new GetFreq_REC(); REC[i]->brUz = brUz; REC[i]->sWitch = 0; } omp_set_nested(1); omp_set_dynamic(0); #pragma omp parallel sections shared(bytes, KAMERA, PROLAZ) num_threads(2) { #pragma omp section { GetImage_RecogDB(hWnd); // *** procedure for image capture from camera } #pragma omp section { DisableProcessWindowsGhosting(); std::this_thread::sleep_for(std::chrono::milliseconds(200)); // time delay // *** images saving loop PROLAZ = 0; // counter while ((PROLAZ < (50 + 300)) && (KAMERA == 0)) { // *** brUzObj = nr. of images per member (300) // *** split captured image to RGB component arrays for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { S_B[i][j] = bytes[(size_t)i * ((size_t)N2 * 3) + (size_t)j * 3]; S_G[i][j] = bytes[(size_t)i * ((size_t)N2 * 3) + (size_t)j * 3 + 1]; S_R[i][j] = bytes[(size_t)i * ((size_t)N2 * 3) + (size_t)j * 3 + 2]; } // *** cut image inside white rectangle (768x768 pix, N = 768) for each component for (i = 0; i < N; i++) for (j = 0; j < N; j++) S_R[i][j] = S_R[i + (N1 - N) / 2][j + (N2 - N) / 2]; for (i = 0; i < N; i++) for (j = 0; j < N; j++) S_G[i][j] = S_G[i + (N1 - N) / 2][j + (N2 - N) / 2]; for (i = 0; i < N; i++) for (j = 0; j < N; j++) S_B[i][j] = S_B[i + (N1 - N) / 2][j + (N2 - N) / 2]; // *** create dir for new member if (PROLAZ == 49) { CreateDirectoryA(".\\MEMBERS\\NEW", NULL); } // *** skip first 50 images for head positioning before saving if (PROLAZ > 49) { Mat frame2; bytesX = new byte[27648]; // 96x96x3 // *** resize image, put image in the buffer and save with imwrite() Reduce_Image_FFTW(N, 96); for (i = 0; i < 96; i++) for (j = 0; j < 96; j++) { bytesX[i * 288 + 3 * j] = (byte)S_B[i][j]; bytesX[i * 288 + 3 * j + 1] = (byte)S_G[i][j]; bytesX[i * 288 + 3 * j + 2] = (byte)S_R[i][j]; } sprintf_s(POM, 200, ".\\MEMBERS\\NEW\\%d.bmp", brUz / brUzObj * 300 + PROLAZ - 49); frame2 = Mat(96, 96, CV_8UC3, bytesX).clone(); imwrite(POM, frame2); delete[] bytesX; } // end while() // *** time delays if (PROLAZ < 50) std::this_thread::sleep_for(std::chrono::milliseconds(300)); else std::this_thread::sleep_for(std::chrono::milliseconds(2)); PROLAZ++; } // end while() if ((PROLAZ > 48) && (KAMERA == 1)) { system("rmdir /Q /S .\\MEMBERS\\NEW"); goto LAB3; } if (PROLAZ == (50 + 300)) { // *** give name to the new member directory LABX: DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, UnesiIme); if (cancel == 1) { system("rmdir /Q /S .\\MEMBERS\\NEW"); goto LAB3; } if ((POM[0] == '\0') || (POM[0] == ' ')) { MessageBox(hWnd, TEXT("Wrong input, try again !"), TEXT("FaceRec9 -> Message:"), MB_OK); goto LABX; } sprintf_s(POM1, 200, ".\\MEMBERS\\%s", POM); sprintf_s(POM2, 200, ".\\MEMBERS\\NEW"); if (rename(POM2, POM1) != 0) { MessageBox(hWnd, TEXT("This name already exists, type new name !"), TEXT("FaceRec9 -> Message:"), MB_OK); goto LABX; } sprintf_s(POM2, 200, "%s\\DB_REC", POM1); CreateDirectoryA(POM2, NULL); sprintf_s(POM2, 200, "%s\\Members30", POM1); CreateDirectoryA(POM2, NULL); // *** databases creation loop PROLAZ = 0; while ((PROLAZ < 300) && (KAMERA == 0)) { Mat frame; bytesX = new byte[27648]; // 96x96x3 // *** load image sprintf_s(POM2, 200, "%s\\%d.bmp", POM1, (brUz / brUzObj * 300 + PROLAZ + 1)); frame = imread(POM2, IMREAD_COLOR); if (frame.empty()) { PROLAZ = -4; goto LAB3; } // *** put image in the buffer size_t size = frame.total() * frame.elemSize(); std::memcpy(bytesX, frame.data, size * sizeof(byte)); // *** split image into RGB component arrays for (i = 0; i < 96; i++) for (j = 0; j < 96; j++) { S_B[i][j] = bytesX[i * 288 + j * 3]; S_G[i][j] = bytesX[i * 288 + j * 3 + 1]; S_R[i][j] = bytesX[i * 288 + j * 3 + 2]; } delete[] bytesX; // *** resize image Reduce_Image_FFTW(96, 52); // *** initialize objects k = 0; for (m = 0; m < 14; m += 13) for (n = 0; n < 27; n += 13) { for (p = 0; p < 26; p++) for (r = 0; r < 26; r++) { REC[k]->SX_R[p][r] = S_R[m + p][n + r]; REC[k]->SX_G[p][r] = S_G[m + p][n + r]; REC[k]->SX_B[p][r] = S_B[m + p][n + r]; } k++; } m = 26; n = 13; for (p = 0; p < 26; p++) for (r = 0; r < 26; r++) { REC[k]->SX_R[p][r] = S_R[m + p][n + r]; REC[k]->SX_G[p][r] = S_G[m + p][n + r]; REC[k]->SX_B[p][r] = S_B[m + p][n + r]; } // *** process objects #pragma omp parallel sections num_threads(2) { #pragma omp section { REC[0]->GetFreq(); REC[1]->GetFreq(); REC[2]->GetFreq(); } #pragma omp section { REC[3]->GetFreq(); REC[4]->GetFreq(); REC[5]->GetFreq(); } } REC[6]->GetFreq(); // *** save freq. to disk sprintf_s(POM2, 200, "%s\\DB_REC\\%d.dat", POM1, brUz / brUzObj * 300 + PROLAZ + 1); if (fopen_s(&stream, POM2, "w+b") == 0) { for (i = 0; i < brObjects; i++) fwrite(REC[i]->X, sizeof(double), (brFreq), stream); fclose(stream); } else { PROLAZ = -5; goto LAB3; } PROLAZ++; } // end while() if (PROLAZ < 300) { sprintf_s(POM2, 200, ".\\MEMBERS\\NEW"); rename(POM1, POM2); system("rmdir /Q /S .\\MEMBERS\\NEW"); goto LAB3; } // *** change data about databases and reboot databases with new member if (PROLAZ == 300) { brUz += brUzObj; if (SpremiPodatke(0) == 0) { PROLAZ = -7; goto LAB3; } brUz -= brUzObj; DestroyDynamicFields(); povrat = CreateDynamicFields(); if (povrat == 0) { PROLAZ = -8; goto LAB3; } PROLAZ = -9; pprolaz = 1; InvalidateRect(hWnd, NULL, TRUE); } } // end if() LAB3: KAMERA = 1; } // pragma inner } // pragma outer if (PROLAZ < 0) { switch (PROLAZ) { case (-1): MessageBox(hWnd, TEXT("Memory allocation for image failed !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-2): MessageBox(hWnd, TEXT("Image not saved !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-3): MessageBox(hWnd, TEXT("Some inputs are wrong !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-4): MessageBox(hWnd, TEXT("Image not read !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-5): MessageBox(hWnd, TEXT("REC data file not saved !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-6): MessageBox(hWnd, TEXT("DET data file not saved !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-7): MessageBox(hWnd, TEXT("brUzoraka.txt or names.txt not saved !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-8): MessageBox(hWnd, TEXT("Dynamic arrays are not properly created !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-9): MessageBox(hWnd, TEXT("New DB Member succesfuly added !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; } } else MessageBox(hWnd, TEXT("New DB Member creation interrupted !"), TEXT("FaceRec9 -> Message:"), MB_OK); delete[]bytes; fftw_cleanup(); cap.release(); } break; // ************************************************************************************* // ***** SELECT AND DELETE DB MEMBER ******************************************* // ************************************************************************************* case ID_RECOGNITIONDB_SELECTANDDELETEDBMEMBER: { if (KAMERA == 0) break; KAMERA = 0; selClan = -1; DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG4), hWnd, IzbaciClanBaze); if (selClan == -1) { KAMERA = 1; break; } i = MessageBox(hWnd, TEXT("Do You want to delete selected DB Member ?"), TEXT("FaceRec9 -> Message:"), MB_OKCANCEL | MB_ICONQUESTION); if (i == IDCANCEL) { KAMERA = 1; break; } DisableProcessWindowsGhosting(); j = selClan * brUzObj; for (i = j; i < j + brUzObj; i++) { sprintf_s(POM, 200, ".\\DAT_DB_REC\\%d.dat", i + 1); DeleteFileA(POM); sprintf_s(POM, 200, ".\\MEMBERS\\%d.bmp", i + 1); DeleteFileA(POM); } for (i = j + brUzObj; i < brUz; i++) { sprintf_s(POM, 200, ".\\DAT_DB_REC\\%d.dat", i + 1); sprintf_s(POM1, 200, ".\\DAT_DB_REC\\%d.dat", i + 1 - brUzObj); rename(POM, POM1); sprintf_s(POM, 200, ".\\MEMBERS\\%d.bmp", i + 1); sprintf_s(POM1, 200, ".\\MEMBERS\\%d.bmp", i + 1 - brUzObj); rename(POM, POM1); } for (k = selClan + 1; k < brUz / brUzObj; k++) { strcpy_s(POM, names[k]); i = 0; while (POM[i] != ' ') i++; for (j = ++i; j < strlen(POM); j++) POM[j - i] = POM[j]; POM[j - i] = '\0'; for (j = 0; j < 300; j++) { sprintf_s(POM1, 200, ".\\MEMBERS\\%s\\DB_REC\\%d.dat", POM, k * 300 + j + 1); sprintf_s(POM2, 200, ".\\MEMBERS\\%s\\DB_REC\\%d.dat", POM, k * 300 + j - 300 + 1); rename(POM1, POM2); sprintf_s(POM1, 200, ".\\MEMBERS\\%s\\%d.bmp", POM, k * 300 + j + 1); sprintf_s(POM2, 200, ".\\MEMBERS\\%s\\%d.bmp", POM, k * 300 + j - 300 + 1); rename(POM1, POM2); } for (j = 0; j < 30; j++) { sprintf_s(POM1, 200, ".\\MEMBERS\\%s\\Members30\\%d.bmp", POM, k * 30 + j + 1); sprintf_s(POM2, 200, ".\\MEMBERS\\%s\\Members30\\%d.bmp", POM, k * 30 + j - 30 + 1); rename(POM1, POM2); } } strcpy_s(POM, names[selClan]); i = 0; while (POM[i] != ' ') i++; for (j = ++i; j < strlen(POM); j++) POM[j - i] = POM[j]; POM[j - i] = '\0'; j = selClan * 300 + 1; for (i = j; i < j + 300; i++) { sprintf_s(POM1, 200, ".\\MEMBERS\\%s\\%d.bmp", POM, i); DeleteFileA(POM1); sprintf_s(POM1, 200, ".\\MEMBERS\\%s\\DB_REC\\%d.dat", POM, i); DeleteFileA(POM1); } j = selClan * 30 + 1; for (i = j; i < j + 30; i++) { sprintf_s(POM1, 200, ".\\MEMBERS\\%s\\Members30\\%d.bmp", POM, i); DeleteFileA(POM1); } sprintf_s(POM1, 200, ".\\MEMBERS\\%s\\DB_REC", POM); RemoveDirectoryA(POM1); sprintf_s(POM1, 200, ".\\MEMBERS\\%s\\Members30", POM); RemoveDirectoryA(POM1); sprintf_s(POM1, 200, ".\\MEMBERS\\%s", POM); RemoveDirectoryA(POM1); for (i = 0; i < brUz / brUzObj; i++) { j = 0; while (names[i][j] != ' ') j++; j++; k = 0; while (names[i][j] != '\0') { names[i][k] = names[i][j]; j++; k++; } names[i][k] = '\0'; } if (fopen_s(&stream, ".\\names.txt", "w+t") == 0) { j = 0; for (i = 0; i < brUz / brUzObj; i++) { if (i == selClan) continue; fprintf_s(stream, "%d. %s\n", j + 1, names[i]); j++; } fprintf_s(stream, "#"); fclose(stream); } else { selClan = -1; KAMERA = 1; MessageBox(hWnd, TEXT("Can not open file names.txt,\n check DB !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; } selClan = -1; DestroyDynamicFields(); brUz -= brUzObj; if (fopen_s(&stream, "brUzoraka.txt", "w+t") == 0) { fprintf_s(stream, "%d,%d#", brUz, brUzObj); fclose(stream); } else { KAMERA = 1; MessageBox(hWnd, TEXT("Can not open file brUzoraka.txt,\n check DB !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; } povrat = CreateDynamicFields(); if (povrat == 1) MessageBox(hWnd, TEXT("DB Member deleted !"), TEXT("FaceRec9 -> Message:"), MB_OK); pprolaz = 1; KAMERA = 1; InvalidateRect(hWnd, NULL, TRUE); } break; // ****************************************************************************** // ***** RECOMPILE RECOGNITION AND DETECTION DATABASE (MEMORY) ********** // ****************************************************************************** case ID_RECOGNITIONDB_RECOMPILERECOGNITIONDATABASE: { if (KAMERA == 0) break; KAMERA = 0; i = MessageBox(hWnd, TEXT("Do You want to recompile Database ?"), TEXT("FaceRec9 -> Message:"), MB_OKCANCEL | MB_ICONQUESTION); if (i == IDCANCEL) { KAMERA = 1; break; } DisableProcessWindowsGhosting(); for (i = 0; i < brObjects; i++) { REC[i] = new GetFreq_REC(); REC[i]->brUz = brUz; REC[i]->sWitch = 0; } PROLAZ = 0; while (PROLAZ < brUz) { Mat frame; bytesX = new byte[27648]; // 96x96x3 // *** load image sprintf_s(POM, 200, ".\\MEMBERS\\%d.bmp", (PROLAZ + 1)); frame = imread(POM, IMREAD_COLOR); if (frame.empty()) { PROLAZ = -2; break; } // *** split image to RGB components size_t size = frame.total() * frame.elemSize(); std::memcpy(bytesX, frame.data, size * sizeof(byte)); for (i = 0; i < 96; i++) for (j = 0; j < 96; j++) { S_B[i][j] = bytesX[i * 288 + j * 3]; S_G[i][j] = bytesX[i * 288 + j * 3 + 1]; S_R[i][j] = bytesX[i * 288 + j * 3 + 2]; } delete[] bytesX; // *** resize image to 52x52 pix Reduce_Image_FFTW(96, 52); k = 0; for (m = 0; m < 14; m += 13) for (n = 0; n < 27; n += 13) { for (p = 0; p < 26; p++) for (r = 0; r < 26; r++) { REC[k]->SX_R[p][r] = S_R[m + p][n + r]; REC[k]->SX_G[p][r] = S_G[m + p][n + r]; REC[k]->SX_B[p][r] = S_B[m + p][n + r]; } k++; } m = 26; n = 13; for (p = 0; p < 26; p++) for (r = 0; r < 26; r++) { REC[k]->SX_R[p][r] = S_R[m + p][n + r]; REC[k]->SX_G[p][r] = S_G[m + p][n + r]; REC[k]->SX_B[p][r] = S_B[m + p][n + r]; } // *** process objects #pragma omp parallel sections num_threads(2) { #pragma omp section { REC[0]->GetFreq(); REC[1]->GetFreq(); REC[2]->GetFreq(); } #pragma omp section { REC[3]->GetFreq(); REC[4]->GetFreq(); REC[5]->GetFreq(); } } REC[6]->GetFreq(); sprintf_s(POM2, 200, ".\\DAT_DB_REC\\%d.dat", PROLAZ + 1); if (fopen_s(&stream, POM2, "w+b") == 0) { for (i = 0; i < brObjects; i++) fwrite(REC[i]->X, sizeof(double), (brFreq), stream); fclose(stream); } else { PROLAZ = -5; break;; } PROLAZ++; } // end while() KAMERA = 1; if (PROLAZ == -1) MessageBox(hWnd, TEXT("Problem opening the file x.dat !"), TEXT("FaceRec9 -> Message:"), MB_OK); else if (PROLAZ == brUz) MessageBox(hWnd, TEXT("Recognition and Detection Database Creation finished !"), TEXT("FaceRec9 -> Message:"), MB_OK); else if (PROLAZ == -2) MessageBox(hWnd, TEXT("Problem reading image x.jpg !"), TEXT("FaceRec9 -> Message:"), MB_OK); else MessageBox(hWnd, TEXT("DataBase creation interrupted !"), TEXT("FaceRec9 -> Message:"), MB_OK); fftw_cleanup(); } break; // ****************************************************************************** // ***** RECOGNITION DB MEMBERS OVERVIEW ******************************** // ****************************************************************************** case ID_OVERVIEW_RECOGNITIONDBMEMBERSOVERVIEW: { DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hWnd, PregledClanovaBaze); } break; // ****************************************************************************** // ***** RECOGNITION DB MEMBERS SELECTION ******************************* // ****************************************************************************** case ID_TOOLS_DBMEMBERSSELECTION: { if (KAMERA == 0) break; KAMERA = 0; selClan = -1; DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG5), hWnd, Create30ElementsDB); if (selClan == -1) { KAMERA = 1; break; } i = MessageBox(hWnd, TEXT("Do You want to create 30 elements DB Member ?"), TEXT("FaceRec9 -> Message:"), MB_OKCANCEL | MB_ICONQUESTION); if (i == IDCANCEL) { KAMERA = 1; break; } DisableProcessWindowsGhosting(); PROLAZ = 0; strcpy_s(POM, names[selClan]); i = 0; while (POM[i] != ' ') i++; for (j = ++i; j < strlen(POM); j++) POM[j - i] = POM[j]; POM[j - i] = '\0'; // *** create dynamic fields int* put = new int[300](); double** G = new double* [300]; for (i = 0; i < 300; i++) G[i] = new double[300](); double*** X_REC = new double** [300]; for (i = 0; i < 300; i++) { X_REC[i] = new double* [(size_t)brObjects]; for (j = 0; j < brObjects; j++) { X_REC[i][j] = new double[brFreq]; } } // *** load recognition DB data for (i = 0; i < 300; i++) { sprintf_s(POM1, 200, ".\\MEMBERS\\%s\\DB_REC\\%d.dat", POM, selClan * 300 + i + 1); if (fopen_s(&stream, POM1, "r+b") == 0) { for (j = 0; j < brObjects; j++) fread(X_REC[i][j], sizeof(double), (brFreq), stream); fclose(stream); } else { PROLAZ = -1; goto LAB4; } } // *** calculate mutual differences between elements // *** in the recognition database // *** creation of G array for (i = 0; i < 300; i++) for (j = 0; j < 300; j++) { for (m = 0; m < brObjects; m++) { pom = 0; for (n = 0; n < brFreq; n++) pom += fabs(X_REC[i][m][n] - X_REC[j][m][n]); G[i][j] += exp(-pow(pom, 10) / 2.0E-7); } G[i][j] /= brObjects; } // *** order elements according to distances *** Distances(G, put); /* // *** save order for selected member sprintf_s(POM1, 200, "%s_All.txt", POM); if (fopen_s(&stream, POM1, "w+t") == 0) { for (i = 0; i < 300; i++) fprintf_s(stream, "%d\n", put[i] + 1); fclose(stream); } else { PROLAZ = -2; goto LAB4; } // *** pick 30 elements from order and save *** poz = 5; sprintf_s(POM1, 200, "%s.txt", POM); if (fopen_s(&stream, POM1, "w+t") == 0) { for (i = poz; i < 300; i += 10) fprintf_s(stream, "%d\n", put[i] + 1); fclose(stream); } else { PROLAZ = -3; goto LAB4; } */ // *** select 30 images out of 300 according to the selected elements, and renumber *** j = 0; for (i = 5; i < 300; i += 10) { sprintf_s(POM1, 200, ".\\MEMBERS\\%s\\%d.bmp", POM, selClan * 300 + put[i] + 1); Mat frame = imread(POM1, IMREAD_COLOR); if (frame.empty()) { PROLAZ = -4; goto LAB4; } sprintf_s(POM1, 200, ".\\MEMBERS\\%s\\MEMBERS30\\%d.bmp", POM, selClan * brUzObj + j + 1); if (!imwrite(POM1, frame)) { PROLAZ = -5; goto LAB4; } sprintf_s(POM1, 200, ".\\MEMBERS\\%d.bmp", selClan * brUzObj + j + 1); if (!imwrite(POM1, frame)) { PROLAZ = -6; goto LAB4; } j++; } LAB4: switch (PROLAZ) { case (0): MessageBox(hWnd, TEXT("Member DB elements selected !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-1): MessageBox(hWnd, TEXT("Recognition DB not loaded !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-2): MessageBox(hWnd, TEXT("Can not open member_All.txt !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-3): MessageBox(hWnd, TEXT("Can not open selected member.txt !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-4): MessageBox(hWnd, TEXT("Can not read selected images !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-5): MessageBox(hWnd, TEXT("Can not write Members30 selected images !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; case (-6): MessageBox(hWnd, TEXT("Can not write selected images !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; } // *** destroy dynamic arrays delete[] put; for (i = 0; i < 300; i++) { for (j = 0; j < brObjects; j++) delete[] X_REC[i][j]; delete[] X_REC[i]; } delete[] X_REC; for (i = 0; i < 300; i++) delete[] G[i]; delete[] G; KAMERA = 1; } break; case ID_TOOLS_MONITORSELECT: { DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG6), hWnd, CheckBoxes); if (cancel == 1) break; sprintf_s(POM, 200, ".\\monitors.dat"); if (fopen_s(&stream, POM, "w+b") == 0) { fwrite(checkBoxes, sizeof(LRESULT), (2), stream); fclose(stream); } else { MessageBox(hWnd, TEXT("Can not open monitors.dat !"), TEXT("FaceRec9 -> Message:"), MB_OK); break; } if (checkBoxes[1] == BST_CHECKED) { XX = GetSystemMetrics(SM_CXSCREEN); YY = -GetSystemMetrics(SM_CYSCREEN); } else { XX = 0; YY = 0; } if (fopen_s(&stream, "resolution.txt", "w+t") == 0) { fprintf_s(stream, "%d %d", XX, YY); fclose(stream); } } break; case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } } break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); HGDIOBJ penGray = CreatePen(NULL, 1, RGB(0, 0, 0)); SelectObject(hdc, GetStockObject(DC_BRUSH)); SetDCBrushColor(hdc, RGB(95, 127, 191)); SelectObject(hdc, penGray); Rectangle(hdc, 0, 0, 468, 90); SelectObject(hdc, GetStockObject(OEM_FIXED_FONT)); SetBkColor(hdc, RGB(95, 127, 191)); SetTextColor(hdc, RGB(0, 0, 0)); sprintf_s(POM, 200, "total Nr. of Patterns: %d", brUz); TextOutA(hdc, 10, 20, POM, (int)strlen(POM)); sprintf_s(POM, 200, "Nr. of Patterns per Object: %d", brUzObj); TextOutA(hdc, 10, 40, POM, (int)strlen(POM)); if (povrat == 1) { SetTextColor(hdc, RGB(63, 191, 63)); sprintf_s(POM, 200, "Dynamic arrays properly created !"); TextOutA(hdc, 10, 60, POM, (int)strlen(POM)); } else { SetTextColor(hdc, RGB(191, 63, 63)); sprintf_s(POM, 200, "Dynamic arrays not created !"); TextOutA(hdc, 10, 60, POM, (int)strlen(POM)); } HGDIOBJ penGreen = CreatePen(NULL, 1, RGB(63, 223, 63)); SelectObject(hdc, GetStockObject(NULL_BRUSH)); SelectObject(hdc, penGreen); Rectangle(hdc, 308, 15, 452, 79); // TODO: Add any drawing code that uses hdc here... EndPaint(hWnd, &ps); } break; case WM_DESTROY: KAMERA = 1; waitKey(300); if (povrat == 1) { DestroyDynamicFields(); } PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: return (INT_PTR)TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; } break; } return (INT_PTR)FALSE; } INT_PTR CALLBACK UnesiIme(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND hDlg1; UNREFERENCED_PARAMETER(lParam); int nLen; switch (message) { case WM_INITDIALOG: hDlg1 = GetDlgItem(hDlg, IDC_EDIT1); SetFocus(hDlg1); return (INT_PTR)FALSE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: hDlg1 = GetDlgItem(hDlg, IDC_EDIT1); // handle to dialog box edit field nLen = GetWindowTextLengthA(hDlg1); GetDlgItemTextA(hDlg, IDC_EDIT1, POM, nLen + 1); POM[nLen] = '\0'; cancel = 0; EndDialog(hDlg, LOWORD(wParam)); break; case IDCANCEL: cancel = 1; EndDialog(hDlg, LOWORD(wParam)); break; } break; default: return (INT_PTR)FALSE; } return (INT_PTR)TRUE; } INT_PTR CALLBACK PregledClanovaBaze(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { int selClan1; switch (message) { case WM_INITDIALOG: { // Add items to list. HWND hwndList = GetDlgItem(hDlg, IDC_LIST1); for (int i = 0; i < brUz / brUzObj; i++) { int pos = (int)SendMessageA(hwndList, LB_ADDSTRING, 0, (LPARAM)names[i]); SendMessage(hwndList, LB_SETITEMDATA, pos, (LPARAM)i); } selClan1 = -1; // Set input focus to the list box. SetFocus(hwndList); return TRUE; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: EndDialog(hDlg, LOWORD(wParam)); return TRUE; case IDC_LIST1: switch (HIWORD(wParam)) { case LBN_SELCHANGE: HWND hwndList = GetDlgItem(hDlg, IDC_LIST1); HWND hwndList1 = GetDlgItem(hDlg, IDC_STATIC); // Get selected index. int lbItem = (int)SendMessage(hwndList, LB_GETCURSEL, 0, 0); // Get item data. selClan1 = (int)SendMessage(hwndList, LB_GETITEMDATA, lbItem, 0); ShowMemberImage(hwndList1, selClan1); return TRUE; } return TRUE; } case WM_DESTROY: EndDialog(hDlg, LOWORD(wParam)); return TRUE; } return FALSE; } INT_PTR CALLBACK IzbaciClanBaze(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { // Add items to list. HWND hwndList = GetDlgItem(hDlg, IDC_LIST1); for (int i = 0; i < brUz / brUzObj; i++) { int pos = (int)SendMessageA(hwndList, LB_ADDSTRING, 0, (LPARAM)names[i]); SendMessage(hwndList, LB_SETITEMDATA, pos, (LPARAM)i); } selClan = -1; // Set input focus to the list box. SetFocus(hwndList); return TRUE; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: selClan = -1; case IDOK: EndDialog(hDlg, LOWORD(wParam)); return TRUE; case IDC_LIST1: switch (HIWORD(wParam)) { case LBN_SELCHANGE: HWND hwndList = GetDlgItem(hDlg, IDC_LIST1); HWND hwndList1 = GetDlgItem(hDlg, IDC_STATIC); // Get selected index. int lbItem = (int)SendMessage(hwndList, LB_GETCURSEL, 0, 0); // Get item data. selClan = (int)SendMessage(hwndList, LB_GETITEMDATA, lbItem, 0); ShowMemberImage(hwndList1, selClan); return TRUE; } return TRUE; } } return FALSE; } INT_PTR CALLBACK Create30ElementsDB(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { // Add items to list. HWND hwndList = GetDlgItem(hDlg, IDC_LIST1); for (int i = 0; i < brUz / brUzObj; i++) { int pos = (int)SendMessageA(hwndList, LB_ADDSTRING, 0, (LPARAM)names[i]); SendMessage(hwndList, LB_SETITEMDATA, pos, (LPARAM)i); } selClan = -1; // Set input focus to the list box. SetFocus(hwndList); return TRUE; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: selClan = -1; case IDOK: // destroyWindow("MemberImage"); EndDialog(hDlg, LOWORD(wParam)); return TRUE; case IDC_LIST1: switch (HIWORD(wParam)) { case LBN_SELCHANGE: HWND hwndList = GetDlgItem(hDlg, IDC_LIST1); HWND hwndList1 = GetDlgItem(hDlg, IDC_STATIC); // Get selected index. int lbItem = (int)SendMessage(hwndList, LB_GETCURSEL, 0, 0); // Get item data. selClan = (int)SendMessage(hwndList, LB_GETITEMDATA, lbItem, 0); ShowMemberImage(hwndList1, selClan); // hwndList1 return TRUE; } return TRUE; } } return FALSE; } INT_PTR CALLBACK CheckBoxes(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND hDlg1; UNREFERENCED_PARAMETER(lParam); int i; switch (message) { case WM_INITDIALOG: for (i = 0; i < 2; i++) { hDlg1 = GetDlgItem(hDlg, i + IDC_RADIO1); SendMessage(hDlg1, BM_SETCHECK, checkBoxes[i], 0); } return (INT_PTR)TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: for (i = 0; i < 2; i++) { hDlg1 = GetDlgItem(hDlg, i + IDC_RADIO1); checkBoxes[i] = SendMessage(hDlg1, BM_GETCHECK, 0, 0); } EndDialog(hDlg, LOWORD(wParam)); break; case IDCANCEL: cancel = 1; EndDialog(hDlg, LOWORD(wParam)); break; } break; default: return (INT_PTR)FALSE; } return (INT_PTR)TRUE; }