|
20 | 20 | compartment_id = "<compartment id>"
|
21 | 21 | input_prefix = "<folder name for images>"
|
22 | 22 | output_prefix = "<output folder name for results>"
|
| 23 | +max_results_per_image = 25 |
23 | 24 |
|
24 | 25 | # Auth Config Definition
|
25 | 26 | config = oci.config.from_file('~/.oci/config')
|
|
49 | 50 | ### Vision AI
|
50 | 51 | # Send the Request to Service with Multiple Features
|
51 | 52 | image_object_detection_feature = ImageObjectDetectionFeature()
|
| 53 | +image_object_detection_feature.max_results = max_results_per_image |
52 | 54 | features = [image_object_detection_feature]
|
53 | 55 |
|
54 | 56 | # Setup Input Location
|
|
76 | 78 | final_prefix= output_prefix+"/"+res.data.id+"/"+namespace_name+"_"+bucket_name+"_"+input_prefix+"/"
|
77 | 79 |
|
78 | 80 | # Logic to perform the following statistics:
|
79 |
| -# 1. Count the number of persons and hardhats in each image, and total up the counts |
80 |
| -# 2. Report the person and hardhat counts, and the number of images processed |
81 |
| -# 3. Also, list the names of images where the person count and hardhat count don’t match |
| 81 | +# 1. Count the number of persons and helmets in each image, and total up the counts |
| 82 | +# 2. Report the person and helmets counts, and the number of images processed |
| 83 | +# 3. Also, list the names of images where the person count and helmets count don’t match |
82 | 84 |
|
83 | 85 | # Wait for images to be processed
|
84 | 86 | print("Wait for images to be analyzed. Timeout after 90 seconds")
|
|
96 | 98 | time.sleep(5)
|
97 | 99 | i+= 1
|
98 | 100 |
|
99 |
| -person_count=0 |
100 |
| -hat_count=0 |
101 |
| -total_person_count=0 |
102 |
| -total_hat_count=0 |
103 |
| -image_counter=0 |
104 |
| -no_match_list=[] |
| 101 | +print("\n") |
| 102 | + |
| 103 | +person_count = 0 |
| 104 | +helmet_count = 0 |
| 105 | +total_person_count = 0 |
| 106 | +total_helmet_count = 0 |
| 107 | +image_counter = 0 |
| 108 | +no_match_list = [] |
105 | 109 |
|
106 | 110 | # List all JSON responses received by Vision AI
|
107 | 111 | object_storage_client = ObjectStorageClient(config)
|
|
111 | 115 | prefix = final_prefix
|
112 | 116 | )
|
113 | 117 |
|
114 |
| -# Count number of persons and number of hats |
| 118 | +# Count number of persons and number of helmets |
115 | 119 | for i in object_list.data.objects:
|
| 120 | + person_count = 0 |
| 121 | + helmet_count = 0 |
| 122 | + |
116 | 123 | image_counter=image_counter+1
|
117 | 124 | body=object_storage_client.get_object(namespace_name, bucket_name, object_name=i.name)
|
118 | 125 | dict_test= json.loads(body.data.content.decode('utf-8'))
|
119 | 126 | for j in dict_test['imageObjects']:
|
120 |
| - if (j['name'] =='Person' or j['name']=='Man' or j['name']=='Woman' or j['name']=='Human'): |
121 |
| - person_count = person_count+1 |
| 127 | + if (j['name'] == 'Person' or j['name'] == 'Man' or j['name'] == 'Woman' or j['name'] == 'Human'): |
| 128 | + person_count = person_count + 1 |
122 | 129 | if (j['name'] == 'Helmet'):
|
123 |
| - hat_count = hat_count+1 |
| 130 | + helmet_count = helmet_count + 1 |
124 | 131 |
|
125 |
| - if (person_count != hat_count): |
| 132 | + if (person_count != helmet_count): |
126 | 133 | no_match_list.append(i.name)
|
127 | 134 |
|
128 | 135 | total_person_count = total_person_count + person_count
|
129 |
| - total_hat_count = total_hat_count + hat_count |
130 |
| - person_count=0 |
131 |
| - hat_count=0 |
| 136 | + total_helmet_count = total_helmet_count + helmet_count |
132 | 137 |
|
133 |
| -print ("Number of persons found in images:", person_count,"\n") |
134 |
| -print ("Number of hardhats found in images:", hat_count, "\n") |
| 138 | +print ("Number of persons found in images:", total_person_count,"\n") |
| 139 | +print ("Number of helmets found in images:", total_helmet_count, "\n") |
135 | 140 | print ("Number of images processed:", image_counter, "\n")
|
136 |
| -print ("Names of images where hat count is not equal to total number of persons:\n") |
| 141 | +print ("Names of images where at least one person is not wearing their helmet:\n") |
137 | 142 |
|
138 | 143 | for i in no_match_list:
|
139 | 144 | i=re.sub(final_prefix,'',i)
|
|
0 commit comments