am using openCV to apply color textures to a wall. When the size of the image is more than 150 Kb then I am able to do the same but when the size of the image is less than 100 kb it doesn’t work properly. If I click on the image it doesn’t work if I click on top of it works. I am assuming it has something to with the dimensions of the image and the screen and the seed point but dont know in which direction to proceed. I am posting the code used below. Any pointers will be really appreciated and if more details are required will update this question
#include “WallPainter.hpp”
using namespace cv;
using namespace std;
Mat WallPainter::paint_wall(Mat image,Point p, cv::Size imageSize, cv::Scalar chosenColor) {
double cannyMinThres = 30.0;
double ratio = 2.5;
Mat mRgbMat = image;
cvtColor(mRgbMat,mRgbMat,COLOR_RGBA2RGB);
Mat mask = Mat(Size(mRgbMat.cols/8.0, mRgbMat.rows/8.0), CV_8UC1, Scalar(0.0));
Mat img ;
mRgbMat.copyTo(img);
Mat mGreyScaleMat;
cvtColor(mRgbMat, mGreyScaleMat,COLOR_RGB2GRAY, 3);
medianBlur(mGreyScaleMat,mGreyScaleMat,3);
Mat cannyGreyMat;
Canny(mGreyScaleMat, cannyGreyMat, cannyMinThres, cannyMinThres*ratio, 3);
//hsv
Mat hsvImage;
cvtColor(img,hsvImage,COLOR_RGB2HSV);
//got the hsv values
vector<Mat> list = vector<Mat>(3);
split(hsvImage, list);
Mat sChannelMat;
vector<Mat> sList = vector<Mat>{list[1]};
// sList.push_back(list[1]);
merge(sList, sChannelMat);
medianBlur(sChannelMat,sChannelMat,3);
// canny
Mat cannyMat;
Canny(sChannelMat, cannyMat, cannyMinThres, cannyMinThres*ratio, 3);
addWeighted(cannyMat,0.5, cannyGreyMat,0.5 ,0.0,cannyMat);
dilate(cannyMat, cannyMat,mask, Point(0.0,0.0), 5);
cout<<mRgbMat.cols<<","<<mRgbMat.rows<<"\n";
double width = imageSize.width;
double height = imageSize.height;
Point seedPoint = Point(p.x*(double(mRgbMat.cols)/width), p.y*(double(mRgbMat.rows)/height));
cout<<seedPoint.x<<","<<seedPoint.y<<"\n";
resize(cannyMat, cannyMat, Size(cannyMat.cols + 2.0, cannyMat.rows + 2.0));
medianBlur(mRgbMat,mRgbMat,15);
int floodFillFlag = 8;
int floodFillResult = floodFill(mRgbMat,cannyMat,seedPoint,chosenColor,0,Scalar(5.0, 5.0, 5.0),Scalar(5.0, 5.0, 5.0),floodFillFlag);
cout<<"paint_wall floodFillResult>>>>>>>>>>>>>>>"<<","<<floodFillResult<<"\n";
dilate(mRgbMat, mRgbMat, mask, Point(0.0,0.0), 5);
//got the hsv of the mask image
Mat rgbHsvImage;
cvtColor(mRgbMat,rgbHsvImage,COLOR_RGB2HSV);
vector<Mat> list1 = vector<Mat>(3);
split(rgbHsvImage, list1);
//merged the "v" of original image with mRgb mat
Mat result;
vector<Mat> newList = vector<Mat>();
newList.push_back(list1[0]);
newList.push_back(list1[1]);
newList.push_back(list[2]);
merge(newList, result);
// converted to rgb
cvtColor(result, result, COLOR_HSV2RGB);
addWeighted(result,0.7, img,0.3 ,0.0,result);
return result;
}