Unverified Commit 0f79b364 authored by tilman's avatar tilman
Browse files

add new images and changed reqs

parent 6a1568ae
......@@ -19,7 +19,7 @@ SHOW_WINDOW = False
SAVE_FILE = not SHOW_WINDOW
TRIANGLES = False
BODY_LINES = True
BISEC_VECTORS = False
BISEC_VECTORS = True
BISEC_CONES = True
GLOBAL_LINE = True
INPAINT_AND_KMEANS = True
......@@ -30,12 +30,13 @@ OVERLAY_ALPHA = 0.2
COLORED_CANVAS = True
BISEC_SKIP_LOWER_LEVELS = False
DISPLAY_RASTER_ELEMENTS = 500
MAX_WIDTH = 1500 #px
KMEANS_AREA_MASK_THRESHOLD = 0.06 #0.08 #max 1.0 (percent of pixels), cur 0.09, sonntag mittag 0.05, #smaller threshold -> more colors, higher threshold -> less colors
KMEANS_K = 7 #10
#KMEANS_K = 6 #10
OUT_DIR = 'images/out/images_imdahl/kmeans_output_canvas/final'
OUT_DIR = 'images/out/asana_task/eccv2020_coco/'
#IN_DIR = "images/first_email/" # images from first email
IN_DIR = "images/images_imdahl/" # images from imdahl
IN_DIR = "images/eccv2020_coco/" # images from imdahl
SKIP_OPENPOSE = False
OPENPOSE_DEMO_KEYPOINTS = np.array([[[4.7613028e+02, 3.3695804e+02, 9.0203685e-01],[5.3667474e+02, 3.8633786e+02, 6.6615295e-01],[5.1645105e+02, 3.8405157e+02, 5.1514143e-01],[0.0000000e+00, 0.0000000e+00, 0.0000000e+00],[0.0000000e+00, 0.0000000e+00, 0.0000000e+00],[5.5459924e+02, 3.8859457e+02, 6.4240879e-01],[5.6353766e+02, 4.7384988e+02, 1.8810490e-01],[5.3886292e+02, 5.2543573e+02, 9.0144195e-02],[5.4566248e+02, 5.3215259e+02, 3.6083767e-01],[5.2768524e+02, 5.3213129e+02, 3.1196830e-01],[5.4556714e+02, 6.3534674e+02, 1.8182488e-01],[5.8149310e+02, 7.2958716e+02, 1.3625422e-01],[5.6579541e+02, 5.3216382e+02, 3.6866242e-01],[5.8822272e+02, 6.2862476e+02, 1.7708556e-01],[6.0843213e+02, 7.2955762e+02, 2.2736737e-01],[4.7597812e+02, 3.2798129e+02, 5.7176876e-01],[4.8729745e+02, 3.3027243e+02, 9.1296065e-01],[0.0000000e+00, 0.0000000e+00, 0.0000000e+00],[5.2090784e+02, 3.3472034e+02, 7.7942842e-01],[5.7928674e+02, 7.5646222e+02, 2.0351715e-01],[5.9049512e+02, 7.5648248e+02, 2.0819387e-01],[6.2183606e+02, 7.3853394e+02, 1.7312977e-01],[5.8145673e+02, 7.5420642e+02, 1.2660497e-01],[5.7701074e+02, 7.5417773e+02, 1.2881383e-01],[5.8374255e+02, 7.3627380e+02, 9.4869599e-02]]
......@@ -80,10 +81,24 @@ for img_name in images:
# Process Image
print("calculating: "+img_name)
img = cv2.imread(img_name)
#resize to max width
scale_percent = MAX_WIDTH/len(img[0]) # percent of original size
if(scale_percent < 1.0):
width = int(img.shape[1] * scale_percent);
height = int(img.shape[0] * scale_percent);
dim = (width, height);
# resize image
img = cv2.resize(img, dim, interpolation = cv2.INTER_AREA);
print("img scaled to:",len(img),len(img[0]))
kmeans_copy = img.copy();
intermediate_output_canvas = img.copy();
output_canvas = np.array([[[255,255,255]]*len(img[0])]*len(img),np.uint8)
max_lw = max(len(img),len(img[0]))
max_lw = len(img);
esz = max_lw / DISPLAY_RASTER_ELEMENTS
if SKIP_OPENPOSE:
if SKIP_OPENPOSE: #skip openpose for debugging, we use already calculated poses then, only works on image nr. 15
datum = DotMap()
datum.poseKeypoints = OPENPOSE_DEMO_KEYPOINTS
print("Skipping OPENPOSE")
......@@ -100,7 +115,7 @@ for img_name in images:
# -> check witch colors are now on the position of the people. The colors participating more than 8% are considered as foreground and replaced by color with the most participation in foreground
# -> output this mask if color information with details is needed.
# -> if binary mask is needed we further do some morph filtering to get away small details and blobs
target = cv2.imread(img_name)
target = kmeans_copy;
#remove cracks and prepare for kmeans
# target = cv2.GaussianBlur(target,(5,5),0) #unsharpen all
# target = cv2.medianBlur(target,33) #remove cracks with with 33 pixel
......@@ -318,47 +333,56 @@ for img_name in images:
cv2.line(output_canvas, trp(linePoints[0]), trp(linePoints[1]), (0,255,0), int(6*esz))
if BISEC_CONES or GLOBAL_LINE:
print("BISEC_CONES",BISEC_CONES);
bisecCones = [poseToBisectCone(pose, max_lw, BISEC_CONE_ANGLE, CORRECTION_ANGLE) for pose in datum.poseKeypoints] #use max(img.height,width) as cone length
bisecCones = [v for v in bisecCones if v] #remove None values
#print([polyToArr(bisecCone) for bisecCone in bisecCones])
intersections = coneIntersections(bisecCones)
maxlevel = max(map(lambda t: len(t), intersections.keys()))
for combi in intersections:
is_not_last_level = len(combi) < maxlevel
if is_not_last_level and BISEC_SKIP_LOWER_LEVELS:
continue;
else:
overlay = np.zeros((len(img),len(img[0]),3), np.uint8)
color = min(((len(combi)-1)*100,255))
alpha = OVERLAY_ALPHA
if DRAW_FIRST_CONE_LAYER_BRIGTHER and len(combi) == 1:
cv2.drawContours(overlay, [polyToArr(intersections[combi])], 0, (0,255,0), -1)
img = overlay_two_image_v2(img, overlay, [0,0,0], (0.25))
if BISEC_CONES:
cv2.drawContours(overlay, [polyToArr(intersections[combi])], 0, (color,0,(0 if is_not_last_level else 255)), -1)
img = overlay_two_image_v2(img, overlay, [0,0,0], (alpha if is_not_last_level else 0.6))
if not is_not_last_level and GLOBAL_LINE: #draw centroid of last polygon
xy = (int(intersections[combi].centroid.x),int(intersections[combi].centroid.y))
global_angle = getGlobalLineAngle(datum.poseKeypoints, CORRECTION_ANGLE)
print("global_angle",np.rad2deg(global_angle))
dist = max_lw
d = (int(dist * np.cos(global_angle)), int(dist * np.sin(global_angle))) #with origin zero
d_l = (int(-dist * np.cos(global_angle)), int(-dist * np.sin(global_angle))) #with origin zero
# draw line with global gaze angle (special mean of all gaze angles) and through center of last intersection
cv2.line(img, xy, (xy[0]+d[0],xy[1]-d[1]), (0,255,255), int(10*esz))
cv2.line(output_canvas, xy, (xy[0]+d[0],xy[1]-d[1]), (0,255,255), int(10*esz))
cv2.line(img, xy, (xy[0]+d_l[0],xy[1]-d_l[1]), (0,255,255), int(10*esz))
cv2.line(output_canvas, xy, (xy[0]+d_l[0],xy[1]-d_l[1]), (0,255,255), int(10*esz))
cv2.circle(img, xy, int(13*esz), (255,255,0), -1)
cv2.circle(output_canvas, xy, int(13*esz), (255,255,0), -1)
if(len(intersections)>0):
maxlevel = max(map(lambda t: len(t), intersections.keys()))
for combi in intersections:
is_not_last_level = len(combi) < maxlevel
if is_not_last_level and BISEC_SKIP_LOWER_LEVELS:
continue;
else:
overlay = np.zeros((len(img),len(img[0]),3), np.uint8)
color = min(((len(combi)-1)*100,255))
alpha = OVERLAY_ALPHA
if DRAW_FIRST_CONE_LAYER_BRIGTHER and len(combi) == 1:
cv2.drawContours(overlay, [polyToArr(intersections[combi])], 0, (0,255,0), -1)
img = overlay_two_image_v2(img, overlay, [0,0,0], (0.25))
intermediate_output_canvas = overlay_two_image_v2(img, overlay, [0,0,0], (alpha if is_not_last_level else 0.6))
if BISEC_CONES:
cv2.drawContours(overlay, [polyToArr(intersections[combi])], 0, (color,0,(0 if is_not_last_level else 255)), -1)
intermediate_output_canvas = overlay_two_image_v2(img, overlay, [0,0,0], (alpha if is_not_last_level else 0.6))
img = overlay_two_image_v2(img, overlay, [0,0,0], (alpha if is_not_last_level else 0.6))
if not is_not_last_level and GLOBAL_LINE: #draw centroid of last polygon
xy = (int(intersections[combi].centroid.x),int(intersections[combi].centroid.y))
global_angle = getGlobalLineAngle(datum.poseKeypoints, CORRECTION_ANGLE)
print("global_angle",np.rad2deg(global_angle))
dist = max_lw
d = (int(dist * np.cos(global_angle)), int(dist * np.sin(global_angle))) #with origin zero
d_l = (int(-dist * np.cos(global_angle)), int(-dist * np.sin(global_angle))) #with origin zero
# draw line with global gaze angle (special mean of all gaze angles) and through center of last intersection
cv2.line(img, xy, (xy[0]+d[0],xy[1]-d[1]), (0,255,255), int(10*esz))
cv2.line(output_canvas, xy, (xy[0]+d[0],xy[1]-d[1]), (0,255,255), int(10*esz))
cv2.line(img, xy, (xy[0]+d_l[0],xy[1]-d_l[1]), (0,255,255), int(10*esz))
cv2.line(output_canvas, xy, (xy[0]+d_l[0],xy[1]-d_l[1]), (0,255,255), int(10*esz))
cv2.circle(img, xy, int(13*esz), (255,255,0), -1)
cv2.circle(output_canvas, xy, int(13*esz), (255,255,0), -1)
else:
print("WARNING-------------------WARNING: no intersections there")
if BISEC_VECTORS:
bisecVectors = [poseToBisectVector(pose, CORRECTION_ANGLE) for pose in datum.poseKeypoints]
for bisecVector in bisecVectors:
if bisecVector is not None:
cv2.arrowedLine(img, trp(bisecVector[1]), trp(bisecVector[0]), (0,0,255), int(4*esz))
cv2.arrowedLine(output_canvas, trp(bisecVector[1]), trp(bisecVector[0]), (0,0,255), int(4*esz))
cv2.arrowedLine(intermediate_output_canvas, trp(bisecVector[1]), trp(bisecVector[0]), (0,0,255), int(4*esz))
if BISEC_CONES or BISEC_VECTORS:
cv2.imwrite(os.path.basename(img_name)+'_bcones_io.jpg',intermediate_output_canvas)
if SAVE_FILE:
#cv2.imwrite(os.path.basename(img_name),img)
if COLORED_CANVAS:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment