Created
March 30, 2018 07:54
-
-
Save ArchdukeTim/d26cf570ed861ce05779bd3ae5c9fe3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import csv | |
################ | |
################ | |
# For this part, I recommend cropping the image so you can really see things. | |
# Whatever you crop it to, save those coordinates | |
THREED_STARTX = 1420 | |
THREED_ENDX = 2030 | |
THREED_STARTY = 1024 | |
THREED_ENDY = 1740 | |
TWOD_STARTX = 1080 | |
TWOD_ENDX = 2200 | |
TWOD_STARTY = 700 | |
TWOD_ENDY = 1507 | |
################# | |
################# | |
reader = csv.DictReader(open('MapFnodes.csv')) | |
reader.fieldnames.append('xcoord3d') | |
reader.fieldnames.append('ycoord3d') | |
img = cv2.imread('01_thefirstfloor.png') | |
threeD = cv2.imread('1-NO-ICONS.png') | |
threeD = threeD[THREED_STARTY:THREED_ENDY, THREED_STARTX:THREED_ENDX] | |
theRow = None | |
def getPos(event, x, y, flags, param): | |
if event == cv2.EVENT_LBUTTONDOWN: | |
theRow['xcoord3d'] = str(x + THREED_STARTX) | |
theRow['ycoord3d'] = str(y + THREED_STARTY) | |
print(theRow) | |
cv2.namedWindow('3d') | |
cv2.setMouseCallback('3d', getPos) | |
for row in reader: | |
theRow = row | |
res = img[TWOD_STARTY:TWOD_ENDY, TWOD_STARTX: TWOD_ENDX] | |
xcord = int((int(row['xcoord']) - TWOD_STARTX)) | |
ycord = int((int(row['ycoord']) - TWOD_STARTY)) | |
cv2.circle(res, (xcord, ycord), 10, (255,0,0), -1) | |
#res = cv2.resize(img, (1920, 1080)) | |
cv2.imshow('2d', res) | |
cv2.imshow('3d', threeD) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() | |
writer = csv.DictWriter(open('MapRnodes.csv', 'w'), fieldnames=reader.fieldnames) | |
writer.writeheader(reader.fieldnames) | |
for row in reader: | |
print(row) | |
writer.writerow(row.values()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment