Python活动日志记录

时间:2013-07-01 18:21:22

标签: python logging

我有关于记录somescript.py的问题 该脚本执行一些操作以查找用户在由于重新格式化和打印页面而变得不可读的某些页面中寻找的单词的匹配。 因此,OCR技术不再适用于我们,所以我想出了一个比较单词的countours来查找匹配的脚本。 该脚本看起来像:

import cv2
from cv2 import *
import numpy as np

method = cv.CV_TM_SQDIFF_NORMED

template_name = "this.png"
image_name = "3.tif"

needle = cv2.imread(template_name)
haystack = cv2.imread(image_name)

# Convert to gray:
needle_g = cv2.cvtColor(needle, cv2.CV_32FC1)
haystack_g = cv2.cvtColor(haystack, cv2.CV_32FC1)

# Attempt match
d = cv2.matchTemplate(needle_g, haystack_g, cv2.cv.CV_TM_SQDIFF_NORMED)


#we want the minimum squared difference
mn,_,mnLoc,_ = cv2.minMaxLoc(d)
print mnLoc

# Draw the rectangle
MPx,MPy = mnLoc

trows,tcols = needle_g.shape[:2]


#Normed methods give better results, ie matchvalue = [1,3,5], others sometimes showserrors
cv2.rectangle(haystack, (MPx,MPy),(MPx+tcols,MPy+trows),(0,0,255),2)




cv2.imshow('output',haystack)

cv2.waitKey(0)
import sys
sys.exit(0)

现在我想记录脚本执行的各种任务,比如

  • 将图像转换为灰度
  • 尝试比赛
  • 绘制矩形

我在stackoverflow上看到了一些脚本,解释了如何记录整个脚本或整个输出但我还没有找到任何只记录一些操作的脚本。

此外,我想添加活动的执行日期和时间。

此外我编写了一个函数来计算输入文件的MD5和SHA1哈希,对于这个特殊情况,即'this.png'和'3.tif',我还没有实现这段代码但这也很容易记录下来吗?

我是一个python-noob,所以如果你们这些人很明显,你知道为什么我自己无法弄明白。

我希望你能帮我解决这个问题!

0 个答案:

没有答案
相关问题