我设置了一个在s3 create object上触发的aws-lambda函数。我使用print语句来尝试确定它不能完成的原因。在我实际调用cv2.matchTemplate调用之前,它到达了这一行。
opencv是通过一个层安装的,请按照以下说明操作:https://itnext.io/create-a-highly-scalable-image-processing-service-on-aws-lambda-and-api-gateway-in-10-minutes-7cbb2893a479
cloudwatch日志中没有给出错误。没有异常的迹象。它就会退出!为什么哦为什么?
我确保lambda函数的超时设置设置为30秒。它在大约10-13秒后退出。
下面是我的日志(从我的自定义日志中截取的密钥、存储桶名称和公司名称):
START RequestId: e8001171-fe9e-41f0-aacc-66bd27626ff5 Version: $LATEST
Downloading file...
Checking result file exists in result bucket
File does not exist in bucket
Loading data from disk
Opening results csv file
Calling algorithm with screenshot
matching...
END RequestId: e8001171-fe9e-41f0-aacc-66bd27626ff5
REPORT RequestId: e8001171-fe9e-41f0-aacc-66bd27626ff5 Duration: 9934.52 ms Billed
Duration: 10000 ms Memory Size: 128 MB Max Memory Used: 129 MB
It then seems to immediatly try to do it again!
RequestId: e8001171-fe9e-41f0-aacc-66bd27626ff5 Process exited before completing request
OpenBLAS WARNING - could not determine the L2 cache size on this system, assuming 256k然后,它似乎会再次尝试一次或两次,并重复自己。
我不知道警告是什么,也不知道该怎么做才能让它开心。也许这就是为什么它正在退出的一个线索。
如果我在本地运行,整个程序运行得很好。我该如何调试这个问题呢?
下面的函数看起来像是在跳出困境。请注意,在匹配完成后,应执行print语句。
def search_for_image_in_image(screenshot_path, detectable_path, epsilon):
"""
Uses template matching algorithm to detect an image within an image
:param screenshot_path: (str) Path to the screenshot to search
:param detectable_path: (str) Path to the detectable to search for
:param epsilon: (float) 1 - the maximum value the algorithm found must be less than this value
in order to be considered a match
:return: (tuple) containing:
(bool) - Whether or not the detectable was found within the screenshot, using the given
epsilon
(float) - Maximum value the algorithm found
(list) - x and y position in the screenshot where the maximum value is located. Or in
other words, where the algorithm thinks the top left of the detectable is most likely to
be (if it is there at all)
"""
screenshot = cv2.imread(screenshot_path, cv2.IMREAD_COLOR)
screenshot = cv2.cvtColor(screenshot, cv2.COLOR_BGR2RGB)
template = cv2.imread(detectable_path, cv2.IMREAD_COLOR)
template = cv2.cvtColor(template, cv2.COLOR_BGR2RGB)
height = template.shape[0]
width = template.shape[1]
# Note that there are several algorithms available.
# Some might not work as well in some cases.
# TODO - Perhaps we should go through each and evaluate the successes and failures
# Like "if 4 out of the 6 agree, then the answer is x"
# But note that would be more computation. Let's look at how long one takes first.
methods = ['cv2.TM_CCOEFF', 'cv2.TM_CCOEFF_NORMED', 'cv2.TM_CCORR', 'cv2.TM_CCORR_NORMED',
'cv2.TM_SQDIFF', 'cv2.TM_SQDIFF_NORMED']
method = eval(methods[1])
print("matching...")
result = cv2.matchTemplate(screenshot, template, method)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
print("done matching...")
if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
top_left = min_loc
else:
top_left = max_loc
bottom_right = (top_left[0] + width, top_left[1] + height)
result_img = screenshot.copy()
cv2.rectangle(result_img, top_left, bottom_right, 255, 2)
print("returning")
return 1.0 - max_val < epsilon, max_val, max_loc发布于 2019-10-08 02:05:00
看起来是内存不足的问题。在lambda的配置中,增加了内存,问题就解决了。
https://stackoverflow.com/questions/58274454
复制相似问题