Computer Vision News - July 2021

3 Summary 1 Turn Your CV Project into an App def run_detection (file_uploaded): st.header("Run detection app") image = Image. pen(file_uploaded) st.set_option('deprecation.showPyplotGlobalUse', False) column1, column2 = st.beta_columns( 2 ) column1.subheader("Input image") st.text("") # Display the input image using matplotlib plt.figure(figsize=( 16 , 16 )) plt.imshow(image) column1.pyplot(use_column_width=True) neural_net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg") labels = [] # Initialize an array to store output labels with open("coco.names", "r") as file: labels = [line.strip() for line in file.readlines()] names_of_layer = neural_net.getLayerNames() output_layers = [names_of_layer[i[ 0 ]- 1 ] for i in neural_net.getUnconnectedOutLayers()] colors = np.random.uniform( 0 , 255 , size=(len(labels), 3 )) newImage = np.array(image.convert('RGB')) img = cv2.cvtColor(newImage, 1 ) height, width, channels = img.shape # Convert the images into blobs blob = cv2.dnn.blobFromImage( img, 0.00391 , ( 416 , 416 ), ( 0 , 0 , 0 ), True, crop=False) neural_net.setInput(blob) # Feed the model with blobs as the input outputs = neural_net.forward(output_layers) classID = [] confidences = [] boxes = [] # Add sliders for confidence threshold and NMS threshold in the sidebar score_threshold = st.sidebar.slider("Confidence_threshold", 0.00 , 1.00 , 0.5 , 0.01 ) nms_threshold = st.sidebar.slider("NMS_threshold", 0.00 , 1.00 , 0.5 , 0.01 ) # Localise detected objects in the image for op in outputs: for detection in op: scores = detection[ 5 :] class_id = np.argmax(scores) confidence = scores[class_id] if confidence > 0.5 : center_x = int(detection[ 0 ] * width) center_y = int(detection[ 1 ] * height) # centre of object w = int(detection[ 2 ] * width) h = int(detection[ 3 ] * height) # Calculate coordinates of bounding box x = int(center_x - w / 2 ) y = int(center_y - h/ 2 ) # Organize the detected objects in an array

RkJQdWJsaXNoZXIy NTc3NzU=