0
votes

i try to develop object detection API,during implementation occur a error,

import cv2
cap = cv2.VideoCapture(0)

with detection_graph.as_default():
 with tf.Session(graph=detection_graph) as sess:
   while(True):
     ret,image_np =cap.read()
     image_np_expanded = np.expand_dims(image_np,axis=0)
     image_tensor =detection_graph.get_tensor_by_name('image_tensor:0')
     boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
     scores = detection_graph.get_tensor_by_name('detection_scores:0')
     classes = detection_graph.get_tensor_by_name('detection_classes:0')
     num_detections = detection_graph.get_tensor_by_name('num_detections:0')

     (boxes,scores,classes,num_detections) = sess.run(
             [boxes,scores,classes,num_detections],
             feed_dict={ image_tensor:image_np_expanded})
     vis_util.visualize_boxes_and_labels_on_image_array(
             image_np,
             np.squeeze(boxes),
             np.squeeze(classes).astype(np.int32),
             np.squeeze(scores),
             category_index,
             use_normalized_coordinates=True,
             line_thickness=8)

     cv2.imshow('image',cv2.resize(image_np,(1280,960)))
     if cv2.waitkey(25) & 0xFF == ord('q'):
         break
         cv2.destroyAllWindows()
         cap.release()
1
can you post the complete error trace? - Jeru Luke
File "C:\Users\Sampath\Anaconda3\lib\site-packages\numpy\core\numeric.py", line 492, in asarray return array(a, dtype, copy=False, order=order) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' - sampath kumara
I don't think that's the complete error traceback, and please post it in the question by editing, and create a minimal reproducible example. - abccd
the integer argument in that particular is empty. Ensure it has a value before running it @sampathkumara - Jeru Luke
@JeruLuke didnt understand - sampath kumara

1 Answers

1
votes

Did you check if the stream is opened properly. You can try it by using the below line.

cap.isOpened()

If above method returns true, it means, there is no problem reading the file. Then, you need to set which frame you want to read using below line.

cap.set(cv2.CAP_PROP_POS_MSEC,frameNumber)

You can simply set the frameNumber to 1000 (in millisec) in case of a live stream!