我想混合兩個圖像。如果它們具有相同的尺寸,則很容易,但是如果其中一個圖像較小或較大,則cv :: addWeighted失敗。使用opencv複製/混合不同大小的圖像
圖片A(預期爲大) 圖片B(預期更小)
我試圖創建一個ROI - 試圖創建A的尺寸的第三圖像,並複製的內部B - I可以似乎沒有對的。請幫忙。
double alpha = 0.7; // something
int min_x = (A.cols - B.cols)/2);
int min_y = (A.rows - B.rows)/2);
int width, height;
if(min_x < 0) {
min_x = 0; width = (*input_images).at(0).cols - 1;
}
else width = (*input_images).at(1).cols - 1;
if(min_y < 0) {
min_y = 0; height = (*input_images).at(0).rows - 1;
}
else height = (*input_images).at(1).rows - 1;
cv::Rect roi = cv::Rect(min_x, min_y, width, height);
cv::Mat larger_image(A);
// not sure how to copy B into roi, or even if it is necessary... and keep the images the same size
cv::addWeighted(larger_image, alpha, A, 1-alpha, 0.0, out_image, A.depth());
即使像cvSetImageROI - 可以工作,但我無法找到C++等同 - 可幫助 - 但我不知道如何使用它仍然保持靜止圖像內容,只有把內部投資回報率的另一個圖像...
您是否希望'out_image'爲(1)與'B'混合的'A'的裁剪部分(即「B」的大小)或(2) 「A」的大小以及與「B」混合的選定部分(因此「A」的大小)? – Jacob
A的大小 - 與選定部分混合B – Thalia
爲什麼'width =(* input_images).at(0).cols - 1'?爲什麼不''(* input_images).at(0).cols'? – Jacob