简体   繁体   English

Python: TypeError: an integer is required (got type module)

[英]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.

相关问题 Python TypeError:整数是必需的(got类型列表) - Python TypeError: an integer is required (got type list) Python:类型错误:需要一个整数(得到类型 str) - Python: TypeError: an integer is required (got type str) TypeError:Python中需要一个整数(类型为str) - TypeError: an integer is required (got type str) in python Python:TypeError 需要 integer(获取类型 str) - Python: TypeError an integer is required(got type str) Python 2-如何修复TypeError:必须为整数(类型为str) - Python 2 - How to fix TypeError: an integer is required (got type str) Python多处理日志记录错误-TypeError:必须为整数(获取类型为NoneType) - Python Multiprocessing Logging Error - TypeError: an integer is required (got type NoneType) Python的HTTP请求:TypeError:需要一个整数(获取类型套接字) - HTTP request with Python : TypeError: an integer is required (got type socket) TypeError:需要一个 integer(获取类型元组)<python><opencv><tesseract></tesseract></opencv></python> - TypeError: an integer is required (got type tuple) <python> <OpenCV> <tesseract> Python - 类型错误:需要一个 integer(获取类型 datetime.datetime) - Python - TypeError: an integer is required (got type datetime.datetime) Python TypeError:需要一个整数(得到类型元组)-(OpenCV / Numpy) - Python TypeError: an integer is required (got type tuple) - (OpenCV / Numpy)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM