color replacement in image for iphone application

前端 未结 2 1428
一生所求
一生所求 2020-12-07 19:44

Basically i want to implement color replacement feature for my paint application. Below are original and expected output

Original:

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 20:14

    I know this answer will be useful to someone someday. try this out in your view viewdidLoad() override method for iOS. image in the code snippet below should be from your UIImageView seed also is fixed.you can make it dynamic based on user tap event.

     cv::Mat mask = cv::Mat::zeros(image.rows + 2, image.cols + 2, CV_8U);
     imageView.image = [self UIImageFromCVMat:image];
     cv::cvtColor(image, image, cv::COLOR_BGR2RGB);
    
      try {
        if(seed.x > 0 && seed.y > 0){
            cv::floodFill(image, mask, seed, cv::Scalar(50, 155, 20) ,0,        cv::Scalar(2,2, 2), cv::Scalar(2,2, 2), 8);
            cv::floodFill(image, mask, seed2, cv::Scalar(50, 155, 20) ,0, cv::Scalar(2,2, 2), cv::Scalar(2,2, 2), 8);
            cv::floodFill(image, mask, seed3, cv::Scalar(50, 155, 0) ,0, cv::Scalar(2,2, 2), cv::Scalar(2,2, 2), 8);
    
        }
    } catch (Exception ex) {
    
    }
    cv::cvtColor(image, image, cv::COLOR_RGB2BGR);
    
    self.imageView.contentMode = UIViewContentModeScaleAspectFill;
    self.imageView.image = [self UIImageFromCVMat:image];
    

提交回复
热议问题