Ask Your Question
-1

Problem in copying part of image to another

asked 2019-08-12 14:26:46 -0600

lalit gravatar image

updated 2019-08-12 14:33:50 -0600

berak gravatar image

How to resolve this problem

>>> img=cv2.imread("d:\\OCR Readers\\CPU images\\50190025579077\\AO_Form_1.jpeg")
>>> img.shape
(1000, 800, 3)
>>> part=img[400:440, 1080:1515]
>>> img2=cv2.imread("d:\\OCR Readers\\white1.png")
>>> img2.shape
(2338, 1651, 3)
>>> img2[15:55, 130:565]=part

ValueError: could not broadcast input array from shape (40,0,3) into shape (40,435,3)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-08-14 06:58:49 -0600

dnns gravatar image

updated 2019-08-14 06:59:16 -0600

Because "part" in your example provides an undefined array. Your Image has the width 1000, but you're indexing 1080 to 1515. There is literatally nothing there to copy. The error message is a bit odd though, I admit.

I tried it out like this:

x = np.zeros((1000,800,3))

y = np.ones((40, 435,3))

x[400:440, 180:180+435] = y

edit flag offensive delete link more

Comments

Thank you very much. got the concept and resolved the problem.

lalit gravatar imagelalit ( 2019-08-14 12:18:33 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-08-12 14:26:46 -0600

Seen: 1,870 times

Last updated: Aug 14 '19