ich bin neu hier und hoffe, dass ich die richtige Robrik gewählt habe.
Ich möchte die Variable top_left in eine Datei umleiten.
Leider bekomme ich eine Fehlermeldung.
Der Befehl print schreibt den Inhalt korrekt in die Konsole dann kommt die Fehlermeldung /zB
(127 , 60)
Traceback (most recent call last)
File* /template_matching py* , line 48, in <module>
datei write(wert
TypeError must be string or buffer, not tuple
Was mich iritiert,dass print damit umgehen kann.
Vielleicht hat ja Jemand eine Info für mich
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('messi5.ppm',0)
img2 = img.copy()
template = cv2.imread('template.ppm',0)
w, h = template.shape[::-1]
methods = ['cv2.TM_SQDIFF']
for meth in methods:
img = img2.copy()
method = eval(meth)
# Apply template Matching
res = cv2.matchTemplate(img,template,method)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
# If the method is TM_SQDIFF or TM_SQDIFF_NORMED, take minimum
if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
top_left = min_loc
else:
top_left = max_loc
bottom_right = (top_left[0] + w, top_left[1] + h)
# top_left = 160 , 100
cv2.rectangle(img,top_left, bottom_right ,255,2)
cv2.imwrite('gesucht.ppm',img)
print top_left
wert = top_left
datei = open("positiontxt","wb")
datei.write(wert)
datei.close()Short
