简体   繁体   中英

how to get a mask of an image so that i can use it in the inpainting function

i want my mask to be black obviously and the red line which is my region of interest to be white so that i can use it inside the inpainting function...! am having this code but it not working

How to concentrate on a particular part of the image... because my mask image is showing all the image... this is the image 在此处输入图片说明 and code
在此处输入图片说明

    cv::inRange(img, cv::Scalar(0, 100, 220), cv::Scalar(10, 255, 255), lower);

    cv::inRange(img, cv::Scalar(0, 10, 100), cv::Scalar(255, 255, 255), upper);

   threshold(mask, mask,10,255, CV_THRESH_BINARY); 

   inpaint(img, mask, inpainted,3,CV_INPAINT_TELEA);
   Mat img = imread("Lennared.jpg"); 

    Mat mask, inpainted;

    cvtcolor(img,mask,CV_BRG2GRAY);

    inrange(img, Scalar(10,10,200), Scalar(40,40,255),mask); // make sure your 
    targeted color is between the range you stated

    inpaint(img,mask, inpainted,3,CV_INPAINT_TELEA);

    for( int key =0 ; 23 !-key; key=waitKey())

    {
        switch (key)
    {
       case 'm' : imshow("maskimage", mask)

    break;

    case 'i': imshow("inpainted image", inpainted)

    break;

    default : imshow("original" img);


    }


    }

    return 0;

since am i trying to detect the red color in the image, i have to pass the scalar value of the red color, that from a lower range to a higher range all inclusive... That should give you the perfect mask image for use in the inpaint function, hope this help everyone else ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM