import os import csv import cv2 as cv allRows = [] newRows = [] with open('palmTables/palm_table.csv') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') line_count = 0 for row in csv_reader: allRows.append(row) path = 'palmdata-1' side_by_side = 'side_by_side' dir_list = os.listdir(path) for fileName in dir_list: if side_by_side in fileName: polygonID = fileName[:13] print(polygonID) for row in allRows: rowPolygonID = row[0] if rowPolygonID == polygonID: newRows.append(row) destination = 'palmdata-1/'+fileName img = cv.imread(destination) org = (0,30) font =cv.FONT_HERSHEY_SIMPLEX fontScale = 1 color = (255,0,0) thickness = 2 text = 'Trees: ' + row[4] + ', ' + 'Area: ' + row[3] + ', ' + 'Avg. Per. Ha.: ' + row[5] cv.putText(img,text,org,font,fontScale,color,thickness,cv.LINE_AA) cv.imwrite(destination,img) break with open('palmTables/palm_table_1_new.csv', 'w', newline='') as file: writer = csv.writer(file) writer.writerow(["Polygon ID", "Farmer Name", "Farmer Phone Number", "Field Area", "Trees", "Avg Per Ha."]) for row in newRows: writer.writerow([row[0],row[1],row[2],row[3],row[4],row[5]])