2012-01-17 42 views
9

Tôi đang cố gắng áp dụng các nhà điều hành Canny ở một vị trí nhất định của một hình ảnh với đoạn mã sau:OpenCV - Kích thước của đối số đầu vào không phù hợp - addWeighted

//region of interest from my RGB image 
Mat devilROI = img(Rect(r->x+lowerRect.x, 
         r->y + lowerRect.y, 
         lowerRect.width, 
         lowerRect.height)); 
Mat canny; 
//to grayscale so I can apply canny 
cvtColor(devilROI, canny, CV_RGB2GRAY); 
//makes my region of interest with Canny 
Canny(canny, canny, low_threshold, high_threshold); 
//back to the original image 
addWeighted(devilROI, 1.0, canny, 0.3, 0., devilROI); 

Và nó được đưa ra cho tôi những lỗi sau khi addWeighted được thực thi:

 
OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in arithm_op, file C:\OpenCV2.3\ opencv\modules\core\src\arithm.cpp, line 1227 
terminate called after throwing an instance of 'cv::Exception' 
what(): C:\OpenCV2.3\opencv\modules\core\src\arithm.cpp:1227: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function arithm_op 

Bạn có bất kỳ đề xuất nào về vấn đề này không? Tôi đã bị kẹt trong thời gian này ...

Cảm ơn bạn.

+0

dòng nào cụ thể sẽ ném lỗi? - đừng lo, tôi thấy đó là 'addWeighted'. –

+0

@ math.coffee addWeighted, đã chỉnh sửa câu hỏi. Cảm ơn. – mrcaramori

Trả lời

9

Dễ dàng. Bạn không có cùng số kênh trong 2 hình ảnh để hợp nhất.

cvtColor(devilROI, canny, CV_RGB2GRAY); 

Chụp ảnh 3 kênh của bạn và biến nó thành hình ảnh có độ cao 1 kênh. Bạn cần cùng một số kênh để sử dụng addWeighted

2

Ok, tôi nghĩ mình đã hiểu.

tôi đã cố gắng sử dụng Mat :: CopyTo, sau đó tôi nhận được: Lỗi

(scn ==1 && (dcn == 3 || dcn == 4)) 

.

Sau đó, tôi tìm thấy this Stackoveflow chủ đề, trong đó đã cho tôi ý tưởng chuyển đổi trở lại RGB, sau đó tôi đã thử các sau đây và nó làm việc:

Mat devilROI = img(Rect(r->x+lowerRect.x, 
         r->y + lowerRect.y, 
         lowerRect.width, 
         lowerRect.height)); 
Mat canny; 
cvtColor(devilROI, canny, CV_BGR2GRAY); 
Canny(canny, canny, low_threshold, high_threshold); 
cvtColor(canny, canny, CV_GRAY2BGR); 
addWeighted(devilROI, 1.0, canny, 0.3, 0., devilROI); 

Vì vậy, nếu có ai có bất cứ đề nghị khác, tôi sẽ là tri ân.

Cảm ơn bạn!

+0

làm thế nào về mã python ?? – Allan

Các vấn đề liên quan