我正在使用Anaconda spyder版本3.3.4和python 3.7 我有以下代码,它显示了这种错误:
File "/Users/sripdeep/Desktop/Tongue_Cancer/createxml.py", line 47
files = os.listdir(XML_PATH)
^
SyntaxError: invalid syntax
如果我甚至不带for循环调用函数,就会在函数声明后显示
我的代码如下:
import random, os, time
from PIL import Image
import xml.dom.minidom as minidom
#import xml.etree.ElementTree as ET
from tonguecrop import *
from lxml import etree
CROP_PATH = '/Users/sripdeep/Desktop/Tongue_Cancer/crop'
NEWXML_PATH = "/Users/sripdeep/Desktop/Tongue_Cancer/newxml"
XML_PATH = "/Users/sripdeep/Desktop/Tongue_Cancer/krupali-sample/annotation"
with Image.open(os.path.join(CROP_PATH, file),'r') as im:
dx , dy = im.size
#print (dx,dy)
def generate_xml(f):
for i in range(1,6):
tree = etree.parse(f)
root = tree.getroot()
#print (root[6][4][0].text)
xmin = int(root[6][4][0].text)
xmin = dx - xmin
root[6][4][0].text = str(xmin)
#print (root[6][4][1].text)
ymin = int(root[6][4][1].text)
ymin = dy - ymin
root[6][4][1].text = str(ymin)
#print (root[6][4][2].text)
xmax = int(root[6][4][2].text)
xmax = dx - xmax
root[6][4][2].text = str(xmax)
#print (root[6][4][3].text)
ymax = int(root[6][4][3].text)
ymax = dy - ymax
root[6][4][3].text = str(ymax)
#print (xmin,ymin,xmax,ymax)
newname = XML_PATH.replace('.', '_{:03d}.'.format(i))
tree.write(open(os.path.join(NEWXML_PATH , newname), 'wb')
files = os.listdir(XML_PATH)
numOfImages = len(files)
for file in files:
with Image.open(os.path.join(XML_PATH, file)) as F:
generate_xml(f)