[英]Python: TypeError: an integer is required (got type module)
i have small code to read all image on folder and send them to current API alternately.我有小代码来读取文件夹上的所有图像并将它们交替发送到当前的 API。 but this code doesn't work yet, how to solve this problem.但是这段代码还没有工作,如何解决这个问题。 thankyou.谢谢你。
import cv2
import os
import json
import requests
import time
vehicle_count = [0]
current_path = os.getcwd() #+ "/"
file = '/image_folder/image' + str(len(vehicle_count)) + ".png"
path = '/home/username/Documents/path/to/image_folder%s' % file
temp_file = current_path + file
result = []
def send_image(source_image):
cv2.imread(temp_file , source_image)
vehicle_count.insert(0, 1)
with open(path, 'rb') as fp:
response = requests.post(
'https://url_to_API/',
files=dict(upload=fp),
headers={'Authorization': 'Token ' + 'MY_API'})
result.append(response.json())
print(json.dumps(result, indent=2));
with open('data.json', 'w') as outfile:
json.dump(result, outfile)
os.remove("%s" %temp_file)
and this is error traceback:这是错误回溯:
Traceback (most recent call last):
File "plate_detection_main.py", line 234, in <module>
object_detection_function()
File "plate_detection_main.py", line 133, in object_detection_function
line_thickness=1,
File "/home/smartron01/Documents/tf-object-counting/vehicle_counting_tensorflow/utils/visualization_utils.py", line 515, in visualize_boxes_and_labels_on_image_array
use_normalized_coordinates=use_normalized_coordinates)
File "/home/smartron01/Documents/tf-object-counting/vehicle_counting_tensorflow/utils/visualization_utils.py", line 128, in draw_bounding_box_on_image_array
use_normalized_coordinates)
File "/home/smartron01/Documents/tf-object-counting/vehicle_counting_tensorflow/utils/visualization_utils.py", line 182, in draw_bounding_box_on_image
predicted_direction, predicted_speed, is_vehicle_detected, update_csv = speed_prediction.predict_speed(top, bottom, right, left, current_frame_number, detected_vehicle_image, ROI_POSITION)
File "/home/smartron01/Documents/tf-object-counting/vehicle_counting_tensorflow/utils/speed_and_direction_prediction_module/speed_prediction.py", line 46, in predict_speed
image_api_sender.send_image(image_saver) # send image to platerecognizer.com
File "/home/smartron01/Documents/tf-object-counting/vehicle_counting_tensorflow/utils/image_utils/image_api_sender.py", line 15, in send_image
cv2.imread(temp_file , source_image)
TypeError: an integer is required (got type module)
The problem is here: cv2.imread(temp_file, source_image)
, you're passing two arguments to the imread()
function where only one is needed.问题在这里: cv2.imread(temp_file, source_image)
,您将两个 arguments 传递给imread()
function ,其中只需要一个。 Try: cv2.imread(temp_file)
given that temp_file is the correct path to the image file you want to load.尝试: cv2.imread(temp_file)
假设 temp_file 是您要加载的图像文件的正确路径。
Note: the second argument that you can pass to the imread(path, flag) function is flag which specifies the way in which image should be read.注意:您可以传递给 imread(path, flag) function 的第二个参数是指定读取图像方式的标志。 It's default value is cv2.IMREAD_COLOR它的默认值为 cv2.IMREAD_COLOR
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.