I have a project in visual studio that can retrieve 2 different x,y coordinates on mouse click now. The coordinates would then be displayed in a textbox. I also have a python script that can crop faces using the x,y coordinates that are picked out on mouse click. The problem I am facing now is that I do not have any idea how to take the coordinates from the textboxes and directly place it in the python script without having to open the python script and change it manually.
import sys, math, Image
def Distance(p1,p2):
dx = p2[0] - p1[0]
dy = p2[1] - p1[1]
return math.sqrt(dx*dx+dy*dy)
def ScaleRotateTranslate(image, angle, center = None, new_center = None, scale = None, resample=Image.BICUBIC):
if (scale is None) and (center is None):
return image.rotate(angle=angle, resample=resample)
nx,ny = x,y = center
sx=sy=1.0
if new_center:
(nx,ny) = new_center
if scale:
(sx,sy) = (scale, scale)
cosine = math.cos(angle)
sine = math.sin(angle)
a = cosine/sx
b = sine/sx
c = x-nx*a-ny*b
d = -sine/sy
e = cosine/sy
f = y-nx*d-ny*e
return image.transform(image.size, Image.AFFINE, (a,b,c,d,e,f), resample=resample)
def CropFace(image, eye_left=(0,0), eye_right=(0,0), offset_pct=(0.2,0.2), dest_sz = (70,70)):
offset_h = math.floor(float(offset_pct[0])*dest_sz[0])
offset_v = math.floor(float(offset_pct[1])*dest_sz[1])
eye_direction = (eye_right[0] - eye_left[0], eye_right[1] - eye_left[1])
rotation = -math.atan2(float(eye_direction[1]),float(eye_direction[0]))
dist = Distance(eye_left, eye_right)
reference = dest_sz[0] - 2.0*offset_h
scale = float(dist)/float(reference)
image = ScaleRotateTranslate(image, center=eye_left, angle=rotation)
crop_xy = (eye_left[0] - scale*offset_h, eye_left[1] - scale*offset_v)
crop_size = (dest_sz[0]*scale, dest_sz[1]*scale)
image = image.crop((int(crop_xy[0]), int(crop_xy[1]), int(crop_xy[0]+crop_size[0]), int(crop_xy[1]+crop_size[1])))
image = image.resize(dest_sz, Image.ANTIALIAS)
return image
if __name__ == "__main__":
image = Image.open("C:\\right135\\right135(1).jpg")
CropFace(image, eye_left=(270,260), eye_right=(342,256), offset_pct=(0.3,0.3), dest_sz=(92,112)).save("C:\\right135\\g.jpg")
Basically now what I would like to achieve is the SECOND LAST LINE of code where CropFace is at, the eye_left and eye_right coordinates can directly be read off the textboxes in my c# windows form and placed in there. Does anyone have any idea?
Please help, thank you.