TypeError: only size-1 arrays can be converted to Python scalars

0 votes
This is my code

for key in bboxes:

bbox = np.array(bboxes[key])

new_boxes, new_probs = roi_helpers.non_max_suppression_fast(bbox, np.array(probs[key]), overlap_thresh=0.5)

for jk in range(new_boxes.shape[0]):

(x1, y1, x2, y2) = new_boxes[jk,:]

cv2.rectangle(img_scaled,(x1, y1), (x2, y2), class_to_color[key],1)

textLabel = '{}: {}'.format(key,int(100*new_probs[jk]))

all_dets.append((key,100*new_probs[jk]))

all_objects.append((key, 1))

(retval,baseLine) = cv2.getTextSize(textLabel,cv2.FONT_HERSHEY_COMPLEX,1,1)

textOrg = (x1, y1-0)

cv2.rectangle(img_scaled, (textOrg[0] - 5, textOrg[1]+baseLine - 5), (textOrg[0]+retval[0] + 5, textOrg[1]-retval[1] - 5), (0, 0, 0), 2)

cv2.rectangle(img_scaled, (textOrg[0] - 5,textOrg[1]+baseLine - 5), (textOrg[0]+retval[0] + 5, textOrg[1]-retval[1] - 5), (255, 255, 255), -1)

cv2.putText(img_scaled, textLabel, textOrg, cv2.FONT_HERSHEY_DUPLEX, 1, (0, 0, 0), 1)

print('Elapsed time = {}'.format(time.time() - st))

height, width, channels = img_scaled.shape

cv2.rectangle(img_scaled, (0,0), (width, 30), (0, 0, 0), -1)

cv2.putText(img_scaled, "Obj count: " + str(list(accumulate(all_objects))), (5, 19), cv2.FONT_HERSHEY_TRIPLEX, 0.5, (255, 255, 255), 1)

cv2.imwrite(os.path.join(output_path, img_name), img_scaled)

print(all_dets)

print("saving to video..")

save_to_video()
May 19 in Python by Rumia
• 120 points

edited May 19 by Gitika 256 views

Hey, @Rumia,

This error occurs as the function called np.int() takes in a single parameter as per its function definition. But if you are passing an array, it will not work and throw the error.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

Pyplot error "only size-1 arrays can be converted to Python scalars"

You can plot the chart by taking ...READ MORE

answered Jan 28, 2019 in Python by Omkar
• 69,030 points
7,660 views
0 votes
0 answers

Python error "only size-1 arrays can be converted to Python scalars"

I'm trying to plot the exponential and ...READ MORE

Jul 9, 2019 in Python by JTM
824 views
0 votes
0 answers

Pyplot error "only size-1 arrays can be converted to Python scalars"

I am getting the following error while ...READ MORE

Nov 28, 2019 in Python by Sumit
• 130 points
1,589 views
+1 vote
0 answers

TypeError: only integer scalar arrays can be converted to a scalar index

import cv2 import numpy as np import matplotlib.pyplot as ...READ MORE

Dec 18, 2019 in Python by sandeep
• 130 points
4,459 views
0 votes
1 answer

Python error "ValueError: size needs to be (int width, int height)" while using pygame.Surface

pygame.Surface takes in integer values for building ...READ MORE

answered Jun 19, 2019 in Python by Varsha
857 views
0 votes
1 answer
+1 vote
1 answer

Can assignment operator be used to copy elements in Python?

Yes assignment operator can be used to ...READ MORE

answered Jul 29, 2019 in Python by Neel
• 3,010 points

edited Jul 30, 2019 by Neel 65 views
0 votes
1 answer
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by aryya
• 7,380 points
260 views