(trajectory)
| 1160 | |
| 1161 | |
| 1162 | def test_task_101(trajectory): |
| 1163 | image_path = "./output/101.png" |
| 1164 | ref_path = "./data/101.jpeg" |
| 1165 | |
| 1166 | # 打开目标图像 |
| 1167 | image = Image.open(image_path) |
| 1168 | |
| 1169 | # 将图像转换为灰度图 |
| 1170 | gray_image = image.convert('L') |
| 1171 | |
| 1172 | # 将灰度图转换为numpy数组 |
| 1173 | gray_array = np.array(gray_image) |
| 1174 | |
| 1175 | # 定义黑色像素的阈值(例如,灰度值小于等于50的像素被认为是黑色) |
| 1176 | black_threshold = 50 |
| 1177 | |
| 1178 | # 计算黑色像素的数量 |
| 1179 | black_pixels = np.sum(gray_array <= black_threshold) |
| 1180 | |
| 1181 | # 计算总像素数量 |
| 1182 | total_pixels = gray_array.size |
| 1183 | |
| 1184 | # 计算黑色像素比例 |
| 1185 | black_ratio = black_pixels / total_pixels |
| 1186 | print(black_ratio) |
| 1187 | # 检查图像中黑色像素的比例是否超过30% |
| 1188 | assert black_ratio > 0.5, "The black pixel percentage does not exceed 50%." |
| 1189 | |
| 1190 | def test_task_102(trajectory): |
| 1191 | image_path = "./output/102.png" |
nothing calls this directly
no outgoing calls
no test coverage detected