diff --git a/conesTest.py b/conesTest.py deleted file mode 100644 index 86bc249be768342a1462d4858a503fa3d1d0d85a..0000000000000000000000000000000000000000 --- a/conesTest.py +++ /dev/null @@ -1,59 +0,0 @@ -from shapely.geometry import Polygon -import numpy as np -import itertools -import cv2 -from lib.bisection import * - -def overlay_two_image_v2(image, overlay, ignore_color=[0,0,0]): - ignore_color = np.asarray(ignore_color) - mask = (overlay==ignore_color).all(-1,keepdims=True) - out = np.where(mask,image,(image * 0.2 + overlay * 0.2).astype(image.dtype)) - return out - -bisecCones = np.array([ - Polygon([[-719, 1205], - [-952, 207], - [ 536, 386], - [-719, 1205]]), - Polygon([[-554, 1264], - [-824, 275], - [ 669, 397], - [-554, 1264]]), - Polygon([[-371, 1444], - [-738, 486], - [ 760, 460], - [-371, 1444]]), - Polygon([[1473, 1200], - [ 653, 1818], - [ 215, 384], - [1473, 1200]]) -]) -img_name = "/Users/Tilman/Documents/Programme/Python/forschungspraktikum/art-structures-env/src/images/images_imdahl/Judas_und_Christus.jpg" -img = cv2.imread(img_name) -orig = img.copy() - - -def overlay_two_image_v2(image, overlay, ignore_color=[0,0,0]): - ignore_color = np.asarray(ignore_color) - mask = (overlay==ignore_color).all(-1,keepdims=True) - out = np.where(mask,image,(image * 0.5 + overlay * 0.5).astype(image.dtype)) - return out - -intersections = coneIntersections(bisecCones) -maxlevel = max(map(lambda t: len(t), intersections.keys())) -for combi in intersections: - #overlay = orig.copy() - is_not_last_level = len(combi) < maxlevel - overlay = np.zeros((len(img),len(img[0]),3), np.uint8) - color = min(((len(combi)-2)*150,255)) - cv2.drawContours(overlay, [polyToArr(intersections[combi])], 0, (color,0,255), -1) - if not is_not_last_level: #draw centroid of last polygon - xy = (int(intersections[combi].centroid.x),int(intersections[combi].centroid.y)) - cv2.circle(overlay, xy, 10, (0,255,0), -1) - img = overlay_two_image_v2(img, overlay, [0,0,0]) - - -cv2.namedWindow(img_name, cv2.WINDOW_NORMAL) -cv2.imshow(img_name, img) -cv2.waitKey(0) -cv2.destroyAllWindows() \ No newline at end of file diff --git a/detect_structures.py b/detect_structures.py index dce7468482a591f80a63089bae5d472f7fccf537..2c6daee89c7783ddc9eaa6a74e8bc70c45fd2bca 100644 --- a/detect_structures.py +++ b/detect_structures.py @@ -60,7 +60,7 @@ for img_name in images: img = datum.cvOutputData #overlay = img.copy() - #print("poses:"+str(len(datum.poseKeypoints))) + print("poses:"+str(datum.poseKeypoints)) if TRIANGLES: triangles = [poseToTriangle(pose) for pose in datum.poseKeypoints] for triangle in triangles: diff --git a/lib/bisection.py b/lib/bisection.py index d9c383d2673cf1395d74effeaff36304bba3f07b..9e8eed02b76f9d79e8349e2d9a93e8408a9f84b1 100644 --- a/lib/bisection.py +++ b/lib/bisection.py @@ -9,20 +9,20 @@ def polyToArr(poly): else: return None -def getAngle(a,b,c, CORRECTION_ANGLE): +def getAngle(a,b,c, CORRECTION_ANGLE): #checked is correct ba = a - b bc = c - b cosine_angle = np.dot(ba, bc) / (np.linalg.norm(ba) * np.linalg.norm(bc)) angle = np.arccos(cosine_angle) - print("angle",angle,np.rad2deg(angle),360-np.rad2deg(angle),180-np.rad2deg(angle)) + #print("angle",angle,np.rad2deg(angle),360-np.rad2deg(angle),180-np.rad2deg(angle)) # TODO get the angle right.... # angle = angle - np.deg2rad(CORRECTION_ANGLE) - if(a[0]-b[0]<0): #check wich direction (left/right) the vector should point - print("left angle",angle,np.rad2deg(angle)) - angle = 360 - angle #- np.deg2rad(CORRECTION_ANGLE) - else: - print("right angle",angle,np.rad2deg(angle)) - angle = 180 - angle #+ np.deg2rad(CORRECTION_ANGLE) + # if(a[0]-b[0]<0): #check wich direction (left/right) the vector should point + # print("left angle",angle,np.rad2deg(angle)) + # angle = 360 - angle #- np.deg2rad(CORRECTION_ANGLE) + # else: + # print("right angle",angle,np.rad2deg(angle)) + # angle = 180 - angle #+ np.deg2rad(CORRECTION_ANGLE) return angle def getGlobalLineAngle(poses, CORRECTION_ANGLE): @@ -30,7 +30,9 @@ def getGlobalLineAngle(poses, CORRECTION_ANGLE): def getBisecPoint(a,b,c, CORRECTION_ANGLE): angle = getAngle(a,b,c, CORRECTION_ANGLE) + print("getBisecPoint-getAngle full",angle,np.rad2deg(angle)) angle = angle / 2 + print("getBisecPoint-getAngle half",angle,np.rad2deg(angle)) dist = la.norm(a-b) # dist = 100 d = (int(dist * np.cos(angle)), int(dist * np.sin(angle))) #with origin zero diff --git a/playground/basic_bisection_vector_test.py b/playground/basic_bisection_vector_test.py index b158d4948334a4fe471595188195a7d573a0165b..57093ab5f38af47424d17925b37cedff1037441c 100644 --- a/playground/basic_bisection_vector_test.py +++ b/playground/basic_bisection_vector_test.py @@ -7,6 +7,8 @@ from shapely.geometry import Polygon from lib.bisection import * +CORRECTION_ANGLE=20 + def trp(point): #trimPoint return (int(point[0]),int(point[1])) @@ -37,11 +39,11 @@ dist1 = la.norm(a-b) dist2 = la.norm(b-c) print("distance",dist1,dist2) -angle = getAngle(a,b,c) +angle = getAngle(a,b,c, CORRECTION_ANGLE) print(np.degrees(angle)) #degress print(angle) #radians #pd = getBisecPoint(a,b,c) -pd1, pd2 = getBisecCone(a,b,c,np.deg2rad(30)) +pd1, pd2 = getBisecCone(a,b,c,np.deg2rad(30),CORRECTION_ANGLE) #cone = np.array([pd1, pd2, b]) conePoly = Polygon([pd1, pd2, b]) @@ -54,11 +56,11 @@ cv2.line(img, pa, pb, (0,255,0)); cv2.line(img, pb, pc, (0,255,0)); cv2.line(img, pb, pd1, (0,0,255)); cv2.line(img, pb, pd2, (0,0,255)); -print(len(img)) -print(len(img[0])) -mainCanvas = Polygon(((0,len(img)), (0,0), (len(img[0]),0), (len(img[0]),len(img)))) -cv2.drawContours(img, [polyToArr(conePoly)], 0, 255, -1) -cv2.drawContours(img, [polyToArr(mainCanvas)], 0, 255, -1) +# print(len(img)) +# print(len(img[0])) +# mainCanvas = Polygon(((0,len(img)), (0,0), (len(img[0]),0), (len(img[0]),len(img)))) +# cv2.drawContours(img, [polyToArr(conePoly)], 0, 255, -1) +# cv2.drawContours(img, [polyToArr(mainCanvas)], 0, 255, -1) cv2.imshow("test", img)