Spaces:
Running
on
Zero
Running
on
Zero
Upload 5 files
Browse files- app.py +0 -1
- confidence_templates.py +6 -0
- enhance_scene_describer.py +1 -1
- lighting_analyzer.py +3 -8
- scene_description.py +1 -1
app.py
CHANGED
|
@@ -640,7 +640,6 @@ def create_interface():
|
|
| 640 |
gr.Examples(
|
| 641 |
examples=[
|
| 642 |
"room_01.jpg",
|
| 643 |
-
"room_02.jpg",
|
| 644 |
"street_04.jpg",
|
| 645 |
"street_05.jpg",
|
| 646 |
"landmark_Louvre_01.jpg",
|
|
|
|
| 640 |
gr.Examples(
|
| 641 |
examples=[
|
| 642 |
"room_01.jpg",
|
|
|
|
| 643 |
"street_04.jpg",
|
| 644 |
"street_05.jpg",
|
| 645 |
"landmark_Louvre_01.jpg",
|
confidence_templates.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
CONFIDENCE_TEMPLATES = {
|
| 3 |
+
"high": "{description} {details}",
|
| 4 |
+
"medium": "This appears to be {description} {details}",
|
| 5 |
+
"low": "This might be {description}, but the confidence is low. {details}"
|
| 6 |
+
}
|
enhance_scene_describer.py
CHANGED
|
@@ -12,7 +12,7 @@ from object_template_fillers import OBJECT_TEMPLATE_FILLERS
|
|
| 12 |
from lighting_conditions import LIGHTING_CONDITIONS
|
| 13 |
from viewpoint_templates import VIEWPOINT_TEMPLATES
|
| 14 |
from cultural_templates import CULTURAL_TEMPLATES
|
| 15 |
-
from
|
| 16 |
from landmark_data import ALL_LANDMARKS
|
| 17 |
|
| 18 |
class EnhancedSceneDescriber:
|
|
|
|
| 12 |
from lighting_conditions import LIGHTING_CONDITIONS
|
| 13 |
from viewpoint_templates import VIEWPOINT_TEMPLATES
|
| 14 |
from cultural_templates import CULTURAL_TEMPLATES
|
| 15 |
+
from confidence_templates import CONFIDENCE_TEMPLATES
|
| 16 |
from landmark_data import ALL_LANDMARKS
|
| 17 |
|
| 18 |
class EnhancedSceneDescriber:
|
lighting_analyzer.py
CHANGED
|
@@ -167,13 +167,12 @@ class LightingAnalyzer:
|
|
| 167 |
# Separate HSV channels
|
| 168 |
h_channel, s_channel, v_channel = cv2.split(hsv_img)
|
| 169 |
|
| 170 |
-
#
|
| 171 |
avg_brightness = np.mean(v_channel)
|
| 172 |
brightness_std = np.std(v_channel)
|
| 173 |
dark_pixel_ratio = np.sum(v_channel < self.config.get("dark_pixel_threshold", 50)) / (height * width) # 使用配置閾值
|
| 174 |
bright_pixel_ratio = np.sum(v_channel > self.config.get("bright_pixel_threshold", 220)) / (height * width) # 新增:亮部像素比例
|
| 175 |
|
| 176 |
-
# --- Color Features ---
|
| 177 |
# Yellow-Orange Ratio
|
| 178 |
yellow_orange_mask = ((h_channel >= 15) & (h_channel <= 45)) # Adjusted range slightly
|
| 179 |
yellow_orange_ratio = np.sum(yellow_orange_mask) / (height * width)
|
|
@@ -183,7 +182,6 @@ class LightingAnalyzer:
|
|
| 183 |
blue_ratio = np.sum(blue_mask) / (height * width)
|
| 184 |
|
| 185 |
# More specific "Sky-Like Blue" Ratio - for clearer skies
|
| 186 |
-
# 中文備註:更精確地定義「天空藍」,排除室內常見的深藍或青色。
|
| 187 |
sky_like_blue_hue_min = self.config.get("sky_blue_hue_min", 100)
|
| 188 |
sky_like_blue_hue_max = self.config.get("sky_blue_hue_max", 130) # Typical sky blue Hues in HSV
|
| 189 |
sky_like_blue_sat_min = self.config.get("sky_blue_sat_min", 60) # Sky is usually somewhat saturated
|
|
@@ -201,8 +199,7 @@ class LightingAnalyzer:
|
|
| 201 |
|
| 202 |
avg_saturation = np.mean(s_channel)
|
| 203 |
|
| 204 |
-
#
|
| 205 |
-
# 中文備註:專門分析圖像頂部區域,這是判斷天空的關鍵。
|
| 206 |
top_third_height = height // 3
|
| 207 |
sky_region_v = v_channel[:top_third_height, :]
|
| 208 |
sky_region_s = s_channel[:top_third_height, :]
|
|
@@ -241,8 +238,7 @@ class LightingAnalyzer:
|
|
| 241 |
else:
|
| 242 |
color_atmosphere = "neutral"
|
| 243 |
|
| 244 |
-
#
|
| 245 |
-
# 中文備註:在縮小的灰階圖像上計算梯度,以提高效率。
|
| 246 |
gx = cv2.Sobel(small_gray, cv2.CV_32F, 1, 0, ksize=3)
|
| 247 |
gy = cv2.Sobel(small_gray, cv2.CV_32F, 0, 1, ksize=3)
|
| 248 |
|
|
@@ -253,7 +249,6 @@ class LightingAnalyzer:
|
|
| 253 |
|
| 254 |
|
| 255 |
# Texture complexity of the top region (potential ceiling or sky)
|
| 256 |
-
# 中文備註:分析頂部區域的紋理複雜度,天空通常紋理簡單,天花板可能複雜。
|
| 257 |
small_top_third_height = small_gray.shape[0] // 3
|
| 258 |
small_sky_region_gray = small_gray[:small_top_third_height, :]
|
| 259 |
if small_sky_region_gray.size > 0:
|
|
|
|
| 167 |
# Separate HSV channels
|
| 168 |
h_channel, s_channel, v_channel = cv2.split(hsv_img)
|
| 169 |
|
| 170 |
+
# Brightness Features
|
| 171 |
avg_brightness = np.mean(v_channel)
|
| 172 |
brightness_std = np.std(v_channel)
|
| 173 |
dark_pixel_ratio = np.sum(v_channel < self.config.get("dark_pixel_threshold", 50)) / (height * width) # 使用配置閾值
|
| 174 |
bright_pixel_ratio = np.sum(v_channel > self.config.get("bright_pixel_threshold", 220)) / (height * width) # 新增:亮部像素比例
|
| 175 |
|
|
|
|
| 176 |
# Yellow-Orange Ratio
|
| 177 |
yellow_orange_mask = ((h_channel >= 15) & (h_channel <= 45)) # Adjusted range slightly
|
| 178 |
yellow_orange_ratio = np.sum(yellow_orange_mask) / (height * width)
|
|
|
|
| 182 |
blue_ratio = np.sum(blue_mask) / (height * width)
|
| 183 |
|
| 184 |
# More specific "Sky-Like Blue" Ratio - for clearer skies
|
|
|
|
| 185 |
sky_like_blue_hue_min = self.config.get("sky_blue_hue_min", 100)
|
| 186 |
sky_like_blue_hue_max = self.config.get("sky_blue_hue_max", 130) # Typical sky blue Hues in HSV
|
| 187 |
sky_like_blue_sat_min = self.config.get("sky_blue_sat_min", 60) # Sky is usually somewhat saturated
|
|
|
|
| 199 |
|
| 200 |
avg_saturation = np.mean(s_channel)
|
| 201 |
|
| 202 |
+
# 專門分析圖像頂部區域,這是判斷天空的關鍵
|
|
|
|
| 203 |
top_third_height = height // 3
|
| 204 |
sky_region_v = v_channel[:top_third_height, :]
|
| 205 |
sky_region_s = s_channel[:top_third_height, :]
|
|
|
|
| 238 |
else:
|
| 239 |
color_atmosphere = "neutral"
|
| 240 |
|
| 241 |
+
# Gradient and Texture Features (on small image for speed)
|
|
|
|
| 242 |
gx = cv2.Sobel(small_gray, cv2.CV_32F, 1, 0, ksize=3)
|
| 243 |
gy = cv2.Sobel(small_gray, cv2.CV_32F, 0, 1, ksize=3)
|
| 244 |
|
|
|
|
| 249 |
|
| 250 |
|
| 251 |
# Texture complexity of the top region (potential ceiling or sky)
|
|
|
|
| 252 |
small_top_third_height = small_gray.shape[0] // 3
|
| 253 |
small_sky_region_gray = small_gray[:small_top_third_height, :]
|
| 254 |
if small_sky_region_gray.size > 0:
|
scene_description.py
CHANGED
|
@@ -7,7 +7,7 @@ from scene_detail_templates import SCENE_DETAIL_TEMPLATES
|
|
| 7 |
from object_template_fillers import OBJECT_TEMPLATE_FILLERS
|
| 8 |
from activity_templates import ACTIVITY_TEMPLATES
|
| 9 |
from safety_templates import SAFETY_TEMPLATES
|
| 10 |
-
from
|
| 11 |
|
| 12 |
class SceneDescriptor:
|
| 13 |
"""
|
|
|
|
| 7 |
from object_template_fillers import OBJECT_TEMPLATE_FILLERS
|
| 8 |
from activity_templates import ACTIVITY_TEMPLATES
|
| 9 |
from safety_templates import SAFETY_TEMPLATES
|
| 10 |
+
from confidence_templates import CONFIDENCE_TEMPLATES
|
| 11 |
|
| 12 |
class SceneDescriptor:
|
| 13 |
"""
|