Unverified Commit 8b5f85bf authored by tilman's avatar tilman
Browse files

working on bdcn postprocessing

parent e5d9981e
......@@ -7,6 +7,10 @@ from sys import platform
from dotmap import DotMap
from shapely.geometry import Polygon
from shapely import affinity
from openpose import pyopenpose as op
params = dict()
#params["model_folder"] = "/Users/Tilman/Documents/Programme/Python/forschungspraktikum/openpose/models/"
params["model_folder"] = os.environ['OPENPOSE_MODELS']
# from openpose import pyopenpose as op
......@@ -35,32 +39,65 @@ images.sort()
images_bdcn.sort()
# os.chdir('../images/out/images_imdahl/filtered_median/') #save images in this dir
datum = DotMap()
datum.poseKeypoints = OPENPOSE_DEMO_KEYPOINTS
#datum = DotMap()
#datum.poseKeypoints = OPENPOSE_DEMO_KEYPOINTS
for img_name, img_bdcn in list(zip(images, images_bdcn))[15:16]: #christus only
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
for img_name, img_bdcn in list(zip(images, images_bdcn)): #christus only
img = cv2.imread(img_name)
bdcn = cv2.imread(img_bdcn)
max_lw = max(len(img),len(img[0]))
esz = max_lw / DISPLAY_RASTER_ELEMENTS
datum = op.Datum()
datum.cvInputData = img
opWrapper.emplaceAndPop([datum])
fposes = np.array([np.array([line[:2] for line in pose if line[2] > 0]) for pose in datum.poseKeypoints]) #filtered poses without zero lines
print("fposes",fposes)
#draw out poses
for pose in fposes:
convexhull = Polygon(pose).convex_hull
sconvexhull = affinity.scale(convexhull, xfact=1.7, yfact=2, origin=convexhull.centroid)
sconvexhull = affinity.scale(convexhull, xfact=1.4, yfact=2, origin=convexhull.centroid)
print(convexhull)
#cv2.line(img, (int(pose[0][0]),int(pose[0][1])), (int(pose[1][0]),int(pose[1][1])), (0,255,0), int(6*esz))
cv2.drawContours(img, [polyToArr(sconvexhull)], 0, 255, int(20*esz))
cv2.drawContours(img, [polyToArr(sconvexhull)], 0, 255, int(10*esz))
cv2.drawContours(img, [polyToArr(sconvexhull)], 0, 255, -1)
cv2.drawContours(bdcn, [polyToArr(sconvexhull)], 0, (255,255,255), int(20*esz))
cv2.drawContours(bdcn, [polyToArr(sconvexhull)], 0, (255,255,255), int(10*esz))
cv2.drawContours(bdcn, [polyToArr(sconvexhull)], 0, (255,255,255), -1)
#draw rectangle
cv2.rectangle(img, (0,0), (len(img[0]),len(img)), (255,0,0), int(40*esz))
cv2.rectangle(bdcn, (0,0), (len(img[0]),len(img)), (255,255,255), int(40*esz))
cv2.namedWindow(img_name, cv2.WINDOW_NORMAL)
cv2.namedWindow(img_name+'bdcn', cv2.WINDOW_NORMAL)
cv2.namedWindow(img_name+'blurred', cv2.WINDOW_NORMAL)
rho=10
theta=180
threshold=2950
minline=int(max_lw/4) #minline 1/6 of image width/heigth
maxgap=int(max_lw/50) #minline 1/12 of image width/heigth
print("params",rho,theta,threshold,minline,maxgap)
#blurred = bdcn.copy()
#cv2.imshow(img_name+'blurred', blurred)
gray = cv2.cvtColor(bdcn, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray,(5,5),0)
# cv2.imshow(img_name+'blurred', blurred)
# cv2.waitKey(0)
lines = cv2.HoughLinesP(image=blurred, rho=rho, theta=np.pi/theta, threshold=threshold, minLineLength=minline, maxLineGap=maxgap)
# if(lines):
if lines is not None:
for line in lines:
x1, y1, x2, y2 = line[0]
cv2.line(bdcn, (x1, y1), (x2, y2), (255, 0, 0), 3)
cv2.imshow(img_name, img)
cv2.imshow(img_name+'blurred', blurred)
cv2.imshow(img_name+'bdcn', bdcn)
cv2.waitKey(0)
......
......@@ -54,7 +54,7 @@ def on_maxgap(val):
update()
def update():
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)
lines = cv.HoughLinesP(image=image, rho=rho, theta=np.pi/theta, threshold=threshold, minLineLength=minline, maxLineGap=maxgap)
# if(lines):
if lines is not None:
for line in lines:
......
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