2013-07-20 3 views
1

4 채널로 구성된 Mat에 대한 투명도를 설정하고 있습니다 (일부 계산 기준). 그러나 이미지를 창에 표시 할 때 이미지에 아무런 변화가 없습니다. 어떤 도움이라도 큰 도움이 될 것입니다.OpenCV의 투명도 설정이 작동하지 않습니다.

void feather_touch(Rect enclosingRect, Mat frame){ 

    Point center(frame.size().width * 0.5, frame.size().height * 0.5); 
    int inclussive_circle_radius = (sqrt((frame.cols * frame.cols + frame.rows * frame.rows)))/2; 
    for(int i = 0; i < frame.rows; i++){ 
     for(int j = 0; j < frame.cols; j++){ 
      Point point(i, j); 
      if(!inRect(point, enclosingRect)){ 
       Vec4b channels = frame.at<Vec4b>(i, j); 
       int dx = center.x - point.x; 
       int dy = center.y - point.y; 
       int dist = sqrt((dx * dx) + (dy * dy)); 
       float alpha = (float)dist/(float)inclussive_circle_radius; 
       int a = (int)((1 - alpha) * 255); 
       frame.at<Vec4b>(i, j)[3] = a; 
      } 
     } 
    } 
} 


bool inRect(cv::Point p,Rect rect) { 
    return p.x >= rect.x && p.x <= (rect.x + rect.width) && p.y >= rect.y && p.y <= (rect.y + rect.height); 
} 
+0

의 중복 가능성 [OpenCV의 : 픽셀의 알파 투명도를 설정하는 방법 (http://stackoverflow.com/questions/16196312/opencv-how-to-set-alpha - 픽셀 투명성) – Aurelius

답변

2

답변 : OpenCV의 imshow은 투명성을 지원하지 않습니다.
addWeighted 기능을 사용하여 교체했습니다. 이제 내 함수는 다음과 같다 :

float alpha = ((float)dist/(float)inclussive_circle_radius); 
//int a = (int)((1 - alpha) * 255); 
//frame.at<Vec4b>(i, j)[3] = a; 
Rect rect(j, i, 1, 1); 
Mat mat = frame(rect); 
Mat sub = layer(rect); 

if(dist > (enclosingRect.width*0.5)){ 
    addWeighted(mat, alpha, sub, 1 - alpha, 0, mat); 
    mat.copyTo(frame(rect)); 
}else{ 
    sub.copyTo(frame(rect)); 
} 
관련 문제