I am learning opencv-python image processing so I wrote this small code but I am getting an error I don't know where I am wrong










-1














This is my code give below for addition of image but it is giving me error



import numpy as np
import cv2

coke = cv2.imread('coca cola.png')
flower = cv2.imread('fall-autumn-red-season.jpg')
img = cv2.addWeighted(coke,0.3,flower,0.7,0)

cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()


and i am getting this error



File "D:/Python codes/image addition.py", line 6, in
img = cv2.addWeighted(coke,0.3,flower,0.7,0)
cv2.error: OpenCV(3.4.3) C:projectsopencv-pythonopencvmodulescoresrcarithm.cpp:659: error: (-209: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 function 'cv::arithm_op'



what should i do to remove the error










share|improve this question























  • From what I understood, you are trying to apply add to 2 pictures of different sizes. Try to resize one image to the size of the second or both to the same size before applying the addWeighted()
    – Osuman AAA
    Nov 11 at 8:08















-1














This is my code give below for addition of image but it is giving me error



import numpy as np
import cv2

coke = cv2.imread('coca cola.png')
flower = cv2.imread('fall-autumn-red-season.jpg')
img = cv2.addWeighted(coke,0.3,flower,0.7,0)

cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()


and i am getting this error



File "D:/Python codes/image addition.py", line 6, in
img = cv2.addWeighted(coke,0.3,flower,0.7,0)
cv2.error: OpenCV(3.4.3) C:projectsopencv-pythonopencvmodulescoresrcarithm.cpp:659: error: (-209: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 function 'cv::arithm_op'



what should i do to remove the error










share|improve this question























  • From what I understood, you are trying to apply add to 2 pictures of different sizes. Try to resize one image to the size of the second or both to the same size before applying the addWeighted()
    – Osuman AAA
    Nov 11 at 8:08













-1












-1








-1







This is my code give below for addition of image but it is giving me error



import numpy as np
import cv2

coke = cv2.imread('coca cola.png')
flower = cv2.imread('fall-autumn-red-season.jpg')
img = cv2.addWeighted(coke,0.3,flower,0.7,0)

cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()


and i am getting this error



File "D:/Python codes/image addition.py", line 6, in
img = cv2.addWeighted(coke,0.3,flower,0.7,0)
cv2.error: OpenCV(3.4.3) C:projectsopencv-pythonopencvmodulescoresrcarithm.cpp:659: error: (-209: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 function 'cv::arithm_op'



what should i do to remove the error










share|improve this question















This is my code give below for addition of image but it is giving me error



import numpy as np
import cv2

coke = cv2.imread('coca cola.png')
flower = cv2.imread('fall-autumn-red-season.jpg')
img = cv2.addWeighted(coke,0.3,flower,0.7,0)

cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()


and i am getting this error



File "D:/Python codes/image addition.py", line 6, in
img = cv2.addWeighted(coke,0.3,flower,0.7,0)
cv2.error: OpenCV(3.4.3) C:projectsopencv-pythonopencvmodulescoresrcarithm.cpp:659: error: (-209: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 function 'cv::arithm_op'



what should i do to remove the error







python opencv3.0






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 10:12









Duco

105




105










asked Nov 11 at 8:02









Shubhanker Tiwari

12




12











  • From what I understood, you are trying to apply add to 2 pictures of different sizes. Try to resize one image to the size of the second or both to the same size before applying the addWeighted()
    – Osuman AAA
    Nov 11 at 8:08
















  • From what I understood, you are trying to apply add to 2 pictures of different sizes. Try to resize one image to the size of the second or both to the same size before applying the addWeighted()
    – Osuman AAA
    Nov 11 at 8:08















From what I understood, you are trying to apply add to 2 pictures of different sizes. Try to resize one image to the size of the second or both to the same size before applying the addWeighted()
– Osuman AAA
Nov 11 at 8:08




From what I understood, you are trying to apply add to 2 pictures of different sizes. Try to resize one image to the size of the second or both to the same size before applying the addWeighted()
– Osuman AAA
Nov 11 at 8:08












1 Answer
1






active

oldest

votes


















0














I cannot test since I do not have the images you are using, but try this code and let me know if it works now. I explained the issue in my comment.



import numpy as np
import cv2

coke = cv2.imread('coca cola.png')
coke1 = cv2.resize(coke,(500, 500), interpolation = cv2.INTER_AREA)
flower = cv2.imread('fall-autumn-red-season.jpg')
flower1 = cv2.resize(flower,(500, 500), interpolation = cv2.INTER_AREA)
img = cv2.addWeighted(coke1,0.3,flower1,0.7,0)

cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()





share|improve this answer






















  • Thanks sir it is working but you made a very small mistake by writing flower2 instead of flower1 but still i corrected it by my self thanks a lot once again
    – Shubhanker Tiwari
    Nov 12 at 11:31










  • You're right ! I corrected it now !!
    – Osuman AAA
    Nov 12 at 12:39










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246865%2fi-am-learning-opencv-python-image-processing-so-i-wrote-this-small-code-but-i-am%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I cannot test since I do not have the images you are using, but try this code and let me know if it works now. I explained the issue in my comment.



import numpy as np
import cv2

coke = cv2.imread('coca cola.png')
coke1 = cv2.resize(coke,(500, 500), interpolation = cv2.INTER_AREA)
flower = cv2.imread('fall-autumn-red-season.jpg')
flower1 = cv2.resize(flower,(500, 500), interpolation = cv2.INTER_AREA)
img = cv2.addWeighted(coke1,0.3,flower1,0.7,0)

cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()





share|improve this answer






















  • Thanks sir it is working but you made a very small mistake by writing flower2 instead of flower1 but still i corrected it by my self thanks a lot once again
    – Shubhanker Tiwari
    Nov 12 at 11:31










  • You're right ! I corrected it now !!
    – Osuman AAA
    Nov 12 at 12:39















0














I cannot test since I do not have the images you are using, but try this code and let me know if it works now. I explained the issue in my comment.



import numpy as np
import cv2

coke = cv2.imread('coca cola.png')
coke1 = cv2.resize(coke,(500, 500), interpolation = cv2.INTER_AREA)
flower = cv2.imread('fall-autumn-red-season.jpg')
flower1 = cv2.resize(flower,(500, 500), interpolation = cv2.INTER_AREA)
img = cv2.addWeighted(coke1,0.3,flower1,0.7,0)

cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()





share|improve this answer






















  • Thanks sir it is working but you made a very small mistake by writing flower2 instead of flower1 but still i corrected it by my self thanks a lot once again
    – Shubhanker Tiwari
    Nov 12 at 11:31










  • You're right ! I corrected it now !!
    – Osuman AAA
    Nov 12 at 12:39













0












0








0






I cannot test since I do not have the images you are using, but try this code and let me know if it works now. I explained the issue in my comment.



import numpy as np
import cv2

coke = cv2.imread('coca cola.png')
coke1 = cv2.resize(coke,(500, 500), interpolation = cv2.INTER_AREA)
flower = cv2.imread('fall-autumn-red-season.jpg')
flower1 = cv2.resize(flower,(500, 500), interpolation = cv2.INTER_AREA)
img = cv2.addWeighted(coke1,0.3,flower1,0.7,0)

cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()





share|improve this answer














I cannot test since I do not have the images you are using, but try this code and let me know if it works now. I explained the issue in my comment.



import numpy as np
import cv2

coke = cv2.imread('coca cola.png')
coke1 = cv2.resize(coke,(500, 500), interpolation = cv2.INTER_AREA)
flower = cv2.imread('fall-autumn-red-season.jpg')
flower1 = cv2.resize(flower,(500, 500), interpolation = cv2.INTER_AREA)
img = cv2.addWeighted(coke1,0.3,flower1,0.7,0)

cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 12:38

























answered Nov 11 at 8:16









Osuman AAA

413212




413212











  • Thanks sir it is working but you made a very small mistake by writing flower2 instead of flower1 but still i corrected it by my self thanks a lot once again
    – Shubhanker Tiwari
    Nov 12 at 11:31










  • You're right ! I corrected it now !!
    – Osuman AAA
    Nov 12 at 12:39
















  • Thanks sir it is working but you made a very small mistake by writing flower2 instead of flower1 but still i corrected it by my self thanks a lot once again
    – Shubhanker Tiwari
    Nov 12 at 11:31










  • You're right ! I corrected it now !!
    – Osuman AAA
    Nov 12 at 12:39















Thanks sir it is working but you made a very small mistake by writing flower2 instead of flower1 but still i corrected it by my self thanks a lot once again
– Shubhanker Tiwari
Nov 12 at 11:31




Thanks sir it is working but you made a very small mistake by writing flower2 instead of flower1 but still i corrected it by my self thanks a lot once again
– Shubhanker Tiwari
Nov 12 at 11:31












You're right ! I corrected it now !!
– Osuman AAA
Nov 12 at 12:39




You're right ! I corrected it now !!
– Osuman AAA
Nov 12 at 12:39

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246865%2fi-am-learning-opencv-python-image-processing-so-i-wrote-this-small-code-but-i-am%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo