MY CURRENT RESULT ------ DESIRED OUTPUT。我正在构建一个移动应用程序,使用户能够从调色板中选择颜色,并为3D图像的颜色部分(例如房间或墙壁)选择颜色。
我当前正在使用iOS的Opencv。我为UIImage创建了一个类别,该类别从用户选择的位置填充到最近的颜色更改。我知道这个问题需要进一步处理。
- (UIImage *)floodFillFromPoint:(cv::Mat)cvMat startPoint:(NSMutableArray* )startPoint endPoint:(NSMutableArray* )endPoint newColor:(ColorsRGB *)newcolor lodiff:(int )diff tap:(int )Taps
{
cv::Mat cvMat2 = cvMat.clone();
cv::cvtColor(cvMat, cvMat, cv::COLOR_BGR2RGB);//in-use
cv::Mat mask;
cv:: Mat edges;
edges = cv::Mat::zeros(500, 500, CV_8UC1);
cv::resize(cvMat, cvMat, cv::Size(500, 500));
cv::Mat grad_x,grad_y,abs_grad_x,abs_grad_y;
cv::Sobel(cvMat, grad_x, CV_16S, 1, 0);
cv::Sobel(cvMat, grad_y, CV_16S, 0, 1);
cv::Canny(grad_x, grad_y,edges, 25, 70,3);
cv::resize(edges, edges, cv::Size(500 + 2, 500 + 2));
for (Pointed* obj in startPoint)
{
cv::Point seed(obj.point1,obj.point2);
double red = 255.0 * newcolor.red;
double green = 255.0 * newcolor.green;
double blue = 255.0 * newcolor.blue;
cv::floodFill(cvMat,edges,seed, cv::Scalar(red,green,blue) ,0, cv::Scalar(2,2,2),cv::Scalar(1,1,1),4);
}
NSData *data = [NSData dataWithBytes:cvMat.data length:cvMat.elemSize()*cvMat.total()];
CGColorSpaceRef colorSpace;
CGBitmapInfo bitmapInfo;
if (cvMat.elemSize() == 1) {
colorSpace = CGColorSpaceCreateDeviceGray();
bitmapInfo = kCGImageAlphaNone | kCGBitmapByteOrderDefault;
} else {
colorSpace = CGColorSpaceCreateDeviceRGB();
bitmapInfo = kCGBitmapByteOrder32Little | (
cvMat.elemSize() == 3? kCGImageAlphaNone : kCGImageAlphaNoneSkipFirst
);
}
CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);
// Creating CGImage from cv::Mat
CGImageRef imageRef = CGImageCreate(
cvMat.cols,
cvMat.rows,
8,
8 * cvMat.elemSize(),
cvMat.step[0],
colorSpace,
bitmapInfo,
provider,
NULL,
false,
kCGRenderingIntentDefault
);
// Getting UIImage from CGImage
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpace);
return finalImage;
}
我希望墙壁上的颜色像生活一样,具有一定程度的光滑度和透明度。但是我的洪水填充输出中有孔,当光线明亮时,它会完全失效。