2014-10-13 4 views
0

현재 내가하고있는 것은 얼굴 이미지를 매트에로드하고 각 눈의 중심점 X 및 Y 좌표를 설정하고 각 눈 주위에 원을 만들고 ROI를 눈 주위의 원으로 설정하는 것입니다 (Rect를 사용하고 마스크를 설정), 눈 이미지의 빨간색 값을 낮 춥니 다.OpenCV : 투명한 마스크를 만드시겠습니까?

수정 된 눈이 검은 색 마스크를 가지고 있기 때문에 수정 된 눈 (붉은 색이 낮아짐)을 원본 이미지 위에 다시 병합하는 것이 문제입니다. 블랙 마스크를 없애는 방법을 모르겠습니다.

나는 현재이 시점에 저를 얻었다 OpenCV의 코드의 비트에 붙어있어 :

원본 이미지 :

검은 마스크

추출 눈 :

수정 된 눈 :

내 문제를 표시

현재 결과 : Getting ROI from a Circle/Point

나의 이해가 왜 당신이 이렇게 원형 투자 수익 (ROI)을 생성 할 수 있다는 것입니다 :

이 여기 내 스레드에서 연속이다 Rect ROI와 블랙 마스크를 사용했습니다. 일반적인 Rect로는 충분하지 않습니다.

많은 조언을드립니다. 고맙습니다.

+1

도니는 다르게 . ;) croppedEye 이미지 (마스크를 사용하여 피부 부분을 제거)를 확인하지만 * write_to/correct * cloneRoi (또는 roi even, 다시 작성할 필요는 없습니다)를 사용하면 copyTo()에 대해? – berak

+0

헤이 @ 버락! Nono, 당신은 나를 너무 많이 도와 줬어! 나는 네가 지금하고있는 말을 얻는다 !! 이것은 내가 현재 가지고있는 것입니다 (코드를 빠르게 변경했습니다) : http://i.imgur.com/4CmL2KJ.jpg 나는 그가 사소한 사고를 당했다고 생각합니다 ... 하. 눈을 잘못 들었을 가능성이 있음을 지금 확인하십시오. – LKB

+1

네, 나는 잘못된 눈을 사용하고있었습니다. :) – LKB

답변

2

당신은 테스트 픽셀 마스크 투자 수익 (ROI) 이미지를 사용하지만 실제 이미지에 작성할 수


cv::Mat plotImage; 
    int radius = 15; 
    float threshold = 1.8; 

    plotImage = cv::imread("C:/temp/debug.jpg", cv::IMREAD_COLOR); 

    cv::Point leftEye(person.GetLeftEyePoint().X, person.GetLeftEyePoint().Y); 
    cv::Point rightEye(person.GetRightEyePoint().X, person.GetRightEyePoint().Y); 

    //get the Rect containing the circle 
    cv::Rect r(leftEye.x-radius, leftEye.y-radius, radius*2, radius*2); 
    //obtain the image ROI 
    cv::Mat roi(plotImage, r); 
    //make a black mask, same size 
    cv::Mat mask(roi.size(), roi.type(), cv::Scalar::all(0)); 
    //with a white filled circle in it 
    cv::circle(mask, cv::Point(radius, radius), radius, cv::Scalar::all(255), -1); 
    //combine roi & mask 
    cv::Mat croppedEye = roi&mask; 

    //conduct red eye detection/removal on croppedEye 
    int count = 0; 
    for(int y=0;y<croppedEye.rows;y++) 
    { 
      for(int x=0;x<croppedEye.cols;x++) 
      { 
        double b = croppedEye.at<cv::Vec3b>(y, x)[0]; 
        double g = croppedEye.at<cv::Vec3b>(y, x)[1]; 
        double r = croppedEye.at<cv::Vec3b>(y, x)[2]; 

        double redIntensity = r/((g + b)/2); 

        //currently causes issues with non-red-eye images 
        if (redIntensity >= threshold) 
        { 
          double newRedValue = (g + b)/2; 
          cv::Vec3b pixelColor(newRedValue,g,b); 
          // 
          // here's the trick now, just write back to the original image ;) 
          // 
          roi.at<cv::Vec3b>(cv::Point(x,y)) = pixelColor; 
          count++; 
        } 
      } 
    } 

    cv::imwrite("C:\\temp\\test.jpg", plotImage); 

enter image description here

+0

다시 한 번 감사드립니다! :) – LKB

+1

즐거움, 그것으로 많은 즐거움을 가지고;) – berak

0

확인이 게시물을. 현재의 문제에 대한 약간의 책임 느낌 Transparent mask

if (imageMask.at<Vec3b>(xx,yy)[0] < 10) 
// This mean If the color of mask in one channel is < 10 replace the original Image 
           { 
                // Copy to original image on (y,x) places the pixel of xx,yy mask 
    OriginalImage.at<Vec3b>(y,x)[0] = imageMask .at<Vec3b>(xx,yy)[0]; 
    OriginalImage.at<Vec3b>(y,x)[1] = imageMask .at<Vec3b>(xx,yy)[1]; 
    OriginalImage.at<Vec3b>(y,x)[2] = imageMask .at<Vec3b>(xx,yy)[2]; 
           } 
관련 문제