Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files245 unmodified lines24624724824925025125225343 unmodified lines297298299300301302303304305306307308309310311312313314315316317318319320321240 unmodified lines56256356456556656756898 unmodified lines66766866967067167267318 unmodified lines692693694695696697698245 unmodified linesif len(ys) == 0 or px_per_ft <= 1e-3:return 0.0d_vals = np.maximum(depth_norm[ys, xs].astype(np.float32), 25.0)# Allow up to 3.2x perspective scaling for deep back walls, floors, and ceilingsrel_scale = np.clip(ref_depth / d_vals, 0.55, 3.2)ft_per_px = (1.0 / px_per_ft) * rel_scalereturn float(np.sum(ft_per_px * ft_per_px)) * float(foreshortening)43 unmodified linesref_depth = max(float(np.median(d_vals)), 30.0) if len(d_vals) > 0 else 128.0return px_per_ft, ref_depth, ref_dim_ft, f"Door Height ({ref_dim_ft:.1f} ft)"# If Door Height was selected but no door exists in the image, default ceiling height to 10.0 fteffective_ceil_ft = 10.0 if cal_mode == "Door Height (ft)" else ref_dim_ftwall_cols = np.where(np.any(masks["wall"] > 0, axis=0))[0]col_heights = []full_col_depths = []for x in wall_cols[::4]:ys = np.where(masks["wall"][:, x] > 0)[0]if len(ys) > 0:span = int(ys[-1] - ys[0])col_heights.append(span)if span >= h * 0.35:full_col_depths.append(float(np.median(depth_norm[ys, x])))median_wall_px = float(np.percentile(col_heights, 65)) if col_heights else h * 0.55px_per_ft = max(median_wall_px / effective_ceil_ft, 5.0)if full_col_depths:ref_depth = max(float(np.median(full_col_depths)), 30.0)else:w_depths = depth_norm[masks["wall"] > 0]ref_depth = max(float(np.median(w_depths)), 30.0) if len(w_depths) > 0 else 128.0240 unmodified linestx = max(8, cx - 65)tag = f"W{idx + 1}: {net_sqft:.0f} sf ({sec_theta:.2f}x)"cv2.putText(overlay, tag, (tx + 2, cy + 2),cv2.FONT_HERSHEY_SIMPLEX, 0.52, (0, 0, 0), 3, cv2.LINE_AA)cv2.putText(98 unmodified lines])payload = {"pipeline_version": "v11","image_size_px": {"width": w, "height": h},"calibration": {"anchor": cal_label,18 unmodified linestotal_px = h * wreport_lines = [f"Pipeline v11 — Foreshortened Net/Gross Area & Takeoff ({cal_label})",f"Walls ({np.count_nonzero(masks['wall']) / total_px * 100:.1f}%): Net Paintable ~{total_net_wall_sqft:.1f} sq.ft | Openings ~{total_deduct_sqft:.1f} sq.ft | Gross ~{total_gross_wall_sqft:.1f} sq.ft ({total_gross_wall_sqft * 0.0929:.1f} sq.m)",f"Floor ({np.count_nonzero(masks['floor']) / total_px * 100:.1f}%): Visible ~{vis_floor_sqft:.1f} sq.ft | Est. Gross Footprint ~{est_gross_floor_sqft:.1f} sq.ft ({est_gross_floor_sqft * 0.0929:.1f} sq.m)",f"Ceiling ({np.count_nonzero(masks['ceiling']) / total_px * 100:.1f}%): Est. ~{ceil_sqft:.1f} sq.ft ({ceil_sqft * 0.0929:.1f} sq.m)",245 unmodified lines24624724824925025125243 unmodified lines296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327240 unmodified lines56856957057157257357498 unmodified lines67367467567667767867918 unmodified lines698699700701702703704245 unmodified linesif len(ys) == 0 or px_per_ft <= 1e-3:return 0.0d_vals = np.maximum(depth_norm[ys, xs].astype(np.float32), 25.0)rel_scale = np.clip(ref_depth / d_vals, 0.5, 3.5)ft_per_px = (1.0 / px_per_ft) * rel_scalereturn float(np.sum(ft_per_px * ft_per_px)) * float(foreshortening)43 unmodified linesref_depth = max(float(np.median(d_vals)), 30.0) if len(d_vals) > 0 else 128.0return px_per_ft, ref_depth, ref_dim_ft, f"Door Height ({ref_dim_ft:.1f} ft)"effective_ceil_ft = 10.0 if cal_mode == "Door Height (ft)" else ref_dim_ft# Pair wall column heights with their exact column depths at the same planewall_cols = np.where(np.any(masks["wall"] > 0, axis=0))[0]col_samples = []for x in wall_cols[::4]:ys = np.where(masks["wall"][:, x] > 0)[0]if len(ys) > 0:span = int(ys[-1] - ys[0])if span >= h * 0.25:col_samples.append((span, float(np.median(depth_norm[ys, x]))))if col_samples:spans = np.array([s[0] for s in col_samples], dtype=np.float32)depths = np.array([s[1] for s in col_samples], dtype=np.float32)target_span = float(np.percentile(spans, 70))matched = (spans >= 0.85 * target_span) & (spans <= 1.15 * target_span)if np.any(matched):paired_span = float(np.median(spans[matched]))ref_depth = max(float(np.median(depths[matched])), 30.0)else:paired_span = target_spanref_depth = max(float(np.median(depths)), 30.0)px_per_ft = max(paired_span / effective_ceil_ft, 5.0)else:px_per_ft = max((h * 0.55) / effective_ceil_ft, 5.0)w_depths = depth_norm[masks["wall"] > 0]ref_depth = max(float(np.median(w_depths)), 30.0) if len(w_depths) > 0 else 128.0240 unmodified linestx = max(8, cx - 65)tag = f"W{idx + 1}: {net_sqft:.0f} sf ({sec_theta:.2f}x)"cv2.putText(overlay, tag, (tx, cy),cv2.FONT_HERSHEY_SIMPLEX, 0.52, (0, 0, 0), 3, cv2.LINE_AA)cv2.putText(98 unmodified lines])payload = {"pipeline_version": "v12","image_size_px": {"width": w, "height": h},"calibration": {"anchor": cal_label,18 unmodified linestotal_px = h * wreport_lines = [f"Pipeline v12 — Depth-Matched Scale & BOQ Takeoff ({cal_label})",f"Walls ({np.count_nonzero(masks['wall']) / total_px * 100:.1f}%): Net Paintable ~{total_net_wall_sqft:.1f} sq.ft | Openings ~{total_deduct_sqft:.1f} sq.ft | Gross ~{total_gross_wall_sqft:.1f} sq.ft ({total_gross_wall_sqft * 0.0929:.1f} sq.m)",f"Floor ({np.count_nonzero(masks['floor']) / total_px * 100:.1f}%): Visible ~{vis_floor_sqft:.1f} sq.ft | Est. Gross Footprint ~{est_gross_floor_sqft:.1f} sq.ft ({est_gross_floor_sqft * 0.0929:.1f} sq.m)",f"Ceiling ({np.count_nonzero(masks['ceiling']) / total_px * 100:.1f}%): Est. ~{ceil_sqft:.1f} sq.ft ({ceil_sqft * 0.0929:.1f} sq.m)",
app.py+22-16