2012-01-17 15 views
9

मैं निम्नलिखित कोड के साथ एक छवि का एक निश्चित स्थान में कैनी ऑपरेटर लागू करने के लिए कोशिश कर रहा हूँ:OpenCV - इनपुट तर्क के आकार से मेल नहीं खाते - 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); 

और यह मुझे निम्न त्रुटि जब दे रहा है addWeighted निष्पादित किया गया है:

 
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 

क्या आपके पास कोई समस्या है कि समस्या क्या हो सकती है? मैं इस पर लंबे समय से फंस गया हूं ...

धन्यवाद।

+0

का उपयोग करने के लिए समान संख्या में चैनलों की आवश्यकता है जो विशेष रूप से त्रुटि को फेंकता है? - कोई चिंता नहीं, मुझे लगता है कि यह 'addWeighted' है। –

+0

@ गणितीय.coffee addWeighted, सवाल संपादित किया। धन्यवाद। – mrcaramori

उत्तर

9

आसान। विलय करने के लिए 2 छवियों में आपके पास समान संख्या में चैनल नहीं हैं।

cvtColor(devilROI, canny, CV_RGB2GRAY); 

आपकी 3 चैनल छवि ले रहा है और इसे 1 चैनल ग्रेस्केल छवि में बदल रहा है। आपको addWeighted

2

ठीक है, मुझे लगता है कि मुझे यह मिला।

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

त्रुटि:

मैं चटाई :: CopyTo उपयोग करने की कोशिश, तो मैं मिला है।

तब मैंने पाया this Stackoveflow विषय है, जो मुझे आरजीबी के लिए वापस परिवर्तित करने का विचार प्रदान किया, तो मैं निम्नलिखित की कोशिश की और यह काम किया:

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); 

तो, अगर किसी को भी किसी भी अन्य सुझाव है, मैं होगा आभारी।

धन्यवाद!

+0

पाइथन कोड के बारे में कैसे ?? – Allan

संबंधित मुद्दे