String eleresi_ut; cout << "Give the absolute path of the image." << endl; cin >> eleresi_ut; Mat img = imread(eleresi_ut + ".png", IMREAD_COLOR); while (img.empty()) { cout << "Error: The desired image couldn't be loaded. Please try again!" << endl; cin >> eleresi_ut; img = imread(eleresi_ut + ".png", IMREAD_COLOR); } cout << "Image successfuly loaded!" << endl; Mat hsv, dest, mask; dest.create(img.rows, img.cols, CV_8UC3); cvtColor(img, hsv, COLOR_BGR2HSV); for (int i = 0; i < img.rows; ++i) { for (int j = 0; j < img.cols; ++j) { Vec3b pixel = hsv.at(i, j); if (pixel[2] <= 10 || (pixel[2] >= 50 && pixel[2] <= 150)){ dest.at(i, j) = img.at(i,j); } } } String hue; cout << "Choose a value for hue in which the text will be shown: " << endl; cin >> hue; int ihue = stoi(hue); Mat s = getStructuringElement(MORPH_ELLIPSE, Size(2, 2)); Mat s1 = getStructuringElement(MORPH_ELLIPSE, Size(1, 1)); Mat s2 = getStructuringElement(MORPH_ELLIPSE, Size(3, 3)); morphologyEx(dest, dest, MORPH_GRADIENT, s); morphologyEx(dest, dest, MORPH_CLOSE, s2); morphologyEx(dest, dest, MORPH_DILATE, s); cvtColor(dest, dest, COLOR_BGR2HSV); for (int i = 0; i < img.rows; ++i) { for (int j = 0; j < img.cols; ++j) { Vec3b pixel = dest.at(i, j); if (pixel[2] > 30 ) { dest.at(i, j)[0] = ihue; } } } cout << "Please provide an absolute path for the image." << endl; String hova; cin >> hova; vector compression; compression.push_back(IMWRITE_JPEG_QUALITY); compression.push_back(92); imwrite(hova + ".jpeg", dest, compression); imshow("result", dest);