For this code please add these features making it be able to : #generate a blank image with black background, picture size is the same as frame #allow it to calculate center point #Draw white circles into the image generated at line 6, diameter is 6

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
For this code please add these features making it be able to : #generate a blank image with black background, picture size is the same as frame #allow it to calculate center point #Draw white circles into the image generated at line 6, diameter is 6
detect3.py - C:\Users\htate2\yolov5\detect3.py (3.9.5)
File Edit Format Run Options Window Help
1 import torch
2 import cv2 as CV
3 import numpy as np
4
5 model = torch.hub.load('ultralytics/yolov5', 'yolov516', pretrained=True)
7 frame = cv.imread('pic25.png')
8 #generate a blank image with black background, picture size is the same as frame
9 #numpy zeros
10 detections = model (frame [..., ::-1])
11 results = detections.pandas ().xyxy [0].to_dict (orient="records")
12 for result in results:
13
con result ['confidence']
14
label
result ['name']
15
x1 = int (result['xmin'])
16
yl = int (result['ymin'])
int (result ['xmax'])
17
x2
18
y2 = int (result ['ymax'])
19
#calculate center of each car
20
#Draw white circles into the image generated at line 6, diameter is 6
img = np.zeros([100, 100,3],dtype=np.uint8)
21
22
img.fill (255) # or img [:] = 255
23
color= (0, 0, 255)
24
print (con, label, xl, yl, x2, y2)
org (x1, yl)
25
26
#font = cv. FONT HERSHEY SIMPLEX
font = cv. FONT HERSHEY PLAIN
27
28
fontScale = 1
29
thickness = 1
30
con1= str (round (con, 2))
31
obj Name = label + str (con1)
32
frame = cv.putText (frame, objName, org, font,
33
fontScale, color, thickness, cv.LINE_AA)
34
cv. rectangle (frame, (x1, yl), (x2, y2), color, thickness)
35
36
frame)
cv.imwrite('result.png',
37 #save image generated
38
Transcribed Image Text:detect3.py - C:\Users\htate2\yolov5\detect3.py (3.9.5) File Edit Format Run Options Window Help 1 import torch 2 import cv2 as CV 3 import numpy as np 4 5 model = torch.hub.load('ultralytics/yolov5', 'yolov516', pretrained=True) 7 frame = cv.imread('pic25.png') 8 #generate a blank image with black background, picture size is the same as frame 9 #numpy zeros 10 detections = model (frame [..., ::-1]) 11 results = detections.pandas ().xyxy [0].to_dict (orient="records") 12 for result in results: 13 con result ['confidence'] 14 label result ['name'] 15 x1 = int (result['xmin']) 16 yl = int (result['ymin']) int (result ['xmax']) 17 x2 18 y2 = int (result ['ymax']) 19 #calculate center of each car 20 #Draw white circles into the image generated at line 6, diameter is 6 img = np.zeros([100, 100,3],dtype=np.uint8) 21 22 img.fill (255) # or img [:] = 255 23 color= (0, 0, 255) 24 print (con, label, xl, yl, x2, y2) org (x1, yl) 25 26 #font = cv. FONT HERSHEY SIMPLEX font = cv. FONT HERSHEY PLAIN 27 28 fontScale = 1 29 thickness = 1 30 con1= str (round (con, 2)) 31 obj Name = label + str (con1) 32 frame = cv.putText (frame, objName, org, font, 33 fontScale, color, thickness, cv.LINE_AA) 34 cv. rectangle (frame, (x1, yl), (x2, y2), color, thickness) 35 36 frame) cv.imwrite('result.png', 37 #save image generated 38
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY