Unverified Commit 702b15cd authored by tilman's avatar tilman
Browse files

add new bise cone work

parent ad13df6b
import numpy as np
import numpy.linalg as la
from shapely.geometry import Polygon
import itertools
def polyToArr(poly):
if poly is not None and poly.exterior is not None:
return np.array(poly.exterior.coords.xy).transpose().astype(int)
else:
return None
def getAngle(a,b,c):
ba = a - b
......@@ -11,7 +19,6 @@ def getAngle(a,b,c):
def getBisecPoint(a,b,c):
angle = getAngle(a,b,c)
if(a[0]-b[0]<0): #check wich direction (left/right) the vector should point
# if(angle < 180):
angle = 360 - angle
else:
angle = 180 - angle
......@@ -21,6 +28,20 @@ def getBisecPoint(a,b,c):
d = (int(dist * np.cos(angle)), int(dist * np.sin(angle))) #with origin zero
return (d[0]+b[0],d[1]+b[1]) #with origin b
def getBisecCone(a,b,c,width):
angle = getAngle(a,b,c)
if(a[0]-b[0]<0): #check wich direction (left/right) the vector should point
angle = 360 - angle
else:
angle = 180 - angle
angle = angle / 2
#dist = la.norm(a-b)
dist = 1500
# dist = 100
conePoint1 = (int(dist * np.cos(angle-(width/2))), int(dist * np.sin(angle-(width/2)))) #with origin zero
conePoint2 = (int(dist * np.cos(angle+(width/2))), int(dist * np.sin(angle+(width/2)))) #with origin zero
return ((conePoint1[0]+b[0],conePoint1[1]+b[1]),(conePoint2[0]+b[0],conePoint2[1]+b[1]))
def poseToBisectVector(pose):
points = pose[[0,1,8]]
if(0.0 in points[:,2:]): #if one point has confidence zero, we can not generate the vector
......@@ -28,4 +49,28 @@ def poseToBisectVector(pose):
a,b,c = points[:,:2] # cut of confidence score so we have normal coordinate points
bisecPoint = getBisecPoint(a,b,c)
return np.array([bisecPoint,b])
#return Polygon([bisecPoint,b])
def poseToBisectCone(pose, angle):
width = np.deg2rad(angle)
points = pose[[0,1,8]]
if(0.0 in points[:,2:]): #if one point has confidence zero, we can not generate the vector
return None
a,b,c = points[:,:2] # cut of confidence score so we have normal coordinate points
conePoint1, conePoint2 = getBisecCone(a,b,c,width)
#return np.array([conePoint1, conePoint2, b])
return Polygon([conePoint1, conePoint2, b])
def coneIntersections(bisecCones):
out = {}
for r in range(2,len(bisecCones)):
pc = list(itertools.combinations(range(0,len(bisecCones)),r))
#print(pc)
for combi in pc:
# print(combi)
intersect = bisecCones[combi[0]]
for i in combi[1:]:
intersect = intersect.intersection(bisecCones[i])
if not intersect.is_empty:
out[combi] = intersect
return out
\ No newline at end of file
import cv2
import numpy as np
import os
IN_DIR = "../images/images_imdahl/"
images = [os.path.join(os.getcwd(), IN_DIR, f) for f in os.listdir(IN_DIR)]
means = np.array([[0,0,0]]*len(images))
i=0
for img_name in images:
img = cv2.imread(img_name)
if img is None:
continue
# print(img_name)
r = img[:,:,0].flatten()
g = img[:,:,1].flatten()
b = img[:,:,2].flatten()
rm = r.sum()/len(r)
gm = g.sum()/len(g)
bm = b.sum()/len(b)
means[i][0] = rm
means[i][1] = gm
means[i][2] = bm
i+=1;
print(rm,gm,bm)
print("global mean",means)
print("r",means[:,0].sum()/len(means));
print("g",means[:,1].sum()/len(means));
print("b",means[:,2].sum()/len(means));
\ No newline at end of file
......@@ -20,17 +20,17 @@ def auto_canny(image, sigma=0.33):
#src1 = cv.imread('/Users/Tilman/Documents/Programme/Python/forschungspraktikum/openpose/examples/media/art/28165_gw.jpg')
#src2 = cv.imread('/Users/Tilman/Documents/Programme/Python/forschungspraktikum/openpose/examples/media/art/38172_gw.jpg')
image = cv.imread('../images/first_email/page_5_item_17_annunci1.jpg')
image = cv.imread('../images/out/fuse_1_bsds500/0.png')
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
blurred = cv.GaussianBlur(gray, (3, 3), 0)
auto = auto_canny(blurred)
rho=3
theta=360
theta=4
threshold=100
minline=100
maxgap=10
minline=220
maxgap=30
def on_rho(val):
global rho
......@@ -53,7 +53,7 @@ def on_maxgap(val):
maxgap=val
update()
def update():
image = cv.imread('../images/first_email/page_5_item_17_annunci1.jpg')
image = cv.imread('../images/out/fuse_1_bsds500/1.png')
lines = cv.HoughLinesP(image=auto, rho=rho, theta=np.pi/theta, threshold=threshold, minLineLength=minline, maxLineGap=maxgap)
# if(lines):
if lines is not None:
......
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