detect colors from object and change its color ios

后端 未结 1 1194
离开以前
离开以前 2021-02-06 19:31

I am using opencv edge and contour detection to crop some objects. now thatt object contain two or more colors so I have to change that colors one by one, for ecample I want to

相关标签:
1条回答
  • 2021-02-06 20:19

    I done it in this way. Hope it would help someone:

    imageView.image=[UIImage imageNamed:@"test.png"];
    cv::Mat img=[self cvMatFromUIImage:imageView.image];
    cv::Mat hsvImage=cvCreateImage(img.size(),8, 3);
    cv::cvtColor(img, hsvImage, CV_BGR2HSV);
    
    std::vector<cv::Mat>channels;
    
    cv::split(hsvImage, channels);
    cv::Mat hue = channels[0];
    cv::Mat dest;
    cv::Mat temp=cvCreateImage(img.size(), 8, 3);
    
    cv::inRange(hsvImage, cv::Scalar(90,50,50), cv::Scalar(130,255,255), dest);
    cv::merge(channels, temp);
    temp.setTo(cv::Scalar(60,255,255),dest);
    cv::split(temp, channels);
    cv::merge(channels, dest);
    cv::cvtColor(dest, hsvImage, CV_HSV2BGR);
    imageView.image=[self UIImageFromCVMat:hsvImage];
    
    0 讨论(0)
提交回复
热议问题