在android中检测并围墙并更改墙面颜色,类似于colorsnap和Asian Paints应用程序

时间:2018-07-11 05:51:26

标签: android android-studio opencv

//  Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.splashscreen);
          //  IplImage image = IplImage.create(bm.getWidth(), bm.getHeight(),IPL_DEPTH_8U, 4);
        IplImage image = cvLoadImage("/Users/nileshsatpute/Documents/OpenCv-for-Android-Color-Detection/app/src/main/res/drawable/splashscreen.png");
            CvSize cvSize = cvGetSize(image);
            IplImage hsvImage = cvCreateImage(cvSize, image.depth(), image.nChannels());
            IplImage hChannel = cvCreateImage(cvSize, image.depth(), 1);
            IplImage sChannel = cvCreateImage(cvSize, image.depth(), 1);
            IplImage vChannel = cvCreateImage(cvSize, image.depth(), 1);
            cvSplit(hsvImage, hChannel, sChannel, vChannel, null);
            IplImage cvInRange = cvCreateImage(cvSize, image.depth(), 1);
            CvScalar source = new CvScalar(72 / 2, 0.07 * 255, 66, 0); //source color to replace
            CvScalar from = getScaler(source, false);
            CvScalar to = getScaler(source, true);
            cvInRangeS(hsvImage, from, to, cvInRange);
            IplImage dest = cvCreateImage(cvSize, image.depth(), image.nChannels());
            IplImage temp = cvCreateImage(cvSize, IPL_DEPTH_8U, 2);
            cvMerge(hChannel, sChannel, null, null, temp);
            cvSet(temp, new opencv_core.CvScalar(45, 255, 0, 0), cvInRange);// destination hue and sat
            cvSplit(temp, hChannel, sChannel, null, null);
            cvMerge(hChannel, sChannel, vChannel, null, dest);
            cvCvtColor(dest, dest, CV_HSV2BGR);
            cvSaveImage("output.png", dest);

0 个答案:

没有答案