QString appPath = QCoreApplication::applicationDirPath(); imagePath = appPath + "/sun.png"; img = cv::imread(imagePath.toStdString()); if (img.empty()) return; imshow("img", img); cv::Mat hsv; cv::cvtColor(img,hsv,COLOR_BGR2HSV); cv::Mat mask; inRange(hsv, Scalar(0,0,221), Scalar(180,30,255), mask); Mat redback = Mat::zeros(img.size(), img.type()); redback = Scalar(40, 40, 200); bitwise_not(mask, mask); imshow("mask", mask); img.copyTo(redback, mask); imshow("roi", redback);