-
Notifications
You must be signed in to change notification settings - Fork 319
添加初步可以生成摄像头的文件 #3245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
添加初步可以生成摄像头的文件 #3245
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
509fdc0
init project
Z-w-7799 28c7fb2
提高行人安全模块成功
Z-w-7799 df1fa59
提高行人安全项目创建成功
Z-w-7799 4bde144
更改项目名称
Z-w-7799 f14ddea
Rename project to enhance_pedestrian_safety
Z-w-7799 18d53ae
封装第三题至函数中 补充第二题函数调用
Z-w-7799 e57b29d
Merge remote-tracking branch 'origin/main'
Z-w-7799 af29be8
添加我的配置需求
Z-w-7799 d56a5b2
Merge branch 'OpenHUTB:main' into main
Z-w-7799 c251745
提交基础生成摄像头文件
Z-w-7799 dcb9f92
Merge remote-tracking branch 'origin/main' into main
Z-w-7799 15b41f0
合并远程更新并解决冲突
Z-w-7799 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/config.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Éú³Éʱ¼ä: 2025-12-15 09:27:19.432740 | ||
| µØÍ¼: Carla/Maps/Town10HD_Opt |
Binary file added
BIN
+492 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+484 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+467 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+469 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+468 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+471 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+470 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+484 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+496 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+500 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+501 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_011.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+504 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_012.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+507 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_013.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+501 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_014.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+498 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_015.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+497 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_016.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+499 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_017.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+498 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_018.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+503 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_019.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+498 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_020.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+493 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_021.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+494 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_022.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+493 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_023.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+488 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+488 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_025.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+492 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_026.png
Oops, something went wrong.
Binary file added
BIN
+491 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_027.png
Oops, something went wrong.
Binary file added
BIN
+492 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_028.png
Oops, something went wrong.
Binary file added
BIN
+496 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_029.png
Oops, something went wrong.
Binary file added
BIN
+499 KB
src/enhance_pedestrian_safety/cvips_data/success_20251215_092719/frame_030.png
Oops, something went wrong.
237 changes: 237 additions & 0 deletions
237
src/enhance_pedestrian_safety/cvips_generation_v1_basic.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,237 @@ | ||
| # cvips_smart_final.py | ||
| """ | ||
| CVIPS æºè½çæ¬ - ä¸åå ³éè¿è¡çCARLAï¼å¹¶ä¿®å¤ææé®é¢ | ||
| """ | ||
|
|
||
| import sys | ||
| import os | ||
| import time | ||
| import random # æ·»å è¿è¡ | ||
| import traceback | ||
| from datetime import datetime | ||
|
|
||
| print("=" * 70) | ||
| print("CVIPS æ°æ®çæå¨ - æºè½çæ¬") | ||
| print("=" * 70) | ||
|
|
||
| # ============================================================ | ||
| # 1. 设置CARLAè·¯å¾ | ||
| # ============================================================ | ||
| print("\n[1/5] 设置CARLAè·¯å¾...") | ||
| CARLA_EGG = r"D:\carla\carla0914\CARLA_0.9.14\WindowsNoEditor\PythonAPI\carla\dist\carla-0.9.14-py3.7-win-amd64.egg" | ||
|
|
||
| if os.path.exists(CARLA_EGG): | ||
| sys.path.append(CARLA_EGG) | ||
| print(f"â CARLAè·¯å¾: {os.path.basename(CARLA_EGG)}") | ||
| else: | ||
| print(f"â æ¾ä¸å°eggæä»¶: {CARLA_EGG}") | ||
| sys.exit(1) | ||
|
|
||
| # ============================================================ | ||
| # 2. å¯¼å ¥CARLA | ||
| # ============================================================ | ||
| print("\n[2/5] å¯¼å ¥CARLA模å...") | ||
| try: | ||
| import carla | ||
|
|
||
| print("â CARLA模åå¯¼å ¥æå") | ||
| except ImportError as e: | ||
| print(f"â å¯¼å ¥å¤±è´¥: {e}") | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| # ============================================================ | ||
| # 3. æºè½è¿æ¥CARLAæå¡å¨ | ||
| # ============================================================ | ||
| def smart_connect_to_carla(max_retries=10, retry_delay=3): | ||
| """æºè½è¿æ¥CARLAæå¡å¨ï¼ä¸å ³éå·²ææå¡å¨""" | ||
| print(f"\n[3/5] è¿æ¥å°CARLAæå¡å¨ (æå¤å°è¯{max_retries}次)...") | ||
|
|
||
| for attempt in range(1, max_retries + 1): | ||
| try: | ||
| print(f" å°è¯ {attempt}/{max_retries}...") | ||
|
|
||
| # å建客æ·ç«¯ | ||
| client = carla.Client('localhost', 2000) | ||
| client.set_timeout(15.0) | ||
|
|
||
| # è·åæå¡å¨çæ¬ | ||
| server_version = client.get_server_version() | ||
| print(f" â è¿æ¥æå! æå¡å¨çæ¬: {server_version}") | ||
|
|
||
| # è·åä¸ç | ||
| world = client.get_world() | ||
| print(f" â å°å¾: {world.get_map().name}") | ||
|
|
||
| return client, world | ||
|
|
||
| except Exception as e: | ||
| error_msg = str(e) | ||
| print(f" å°è¯ {attempt} 失败: {error_msg[:80]}...") | ||
|
|
||
| # ç»åºå ·ä½å»ºè®® | ||
| if "time-out" in error_msg: | ||
| if attempt == 1: | ||
| print(f" ⹠请确ä¿CARLAæå¡å¨æ£å¨è¿è¡") | ||
| print(f" â¹ å¦æCARLAæ£å¨å¯å¨ä¸ï¼è¯·çå¾ å ç§é") | ||
| elif attempt == 3: | ||
| print(f" â¹ å¦æCARLAçªå£æ ååºï¼è¯·å°è¯å¨çªå£ä¸ç¹å»ä¸ä¸") | ||
|
|
||
| if attempt < max_retries: | ||
| print(f" çå¾ {retry_delay} ç§åéè¯...") | ||
| time.sleep(retry_delay) | ||
| else: | ||
| print(f"\nâ ææè¿æ¥å°è¯å¤±è´¥") | ||
| print(f"\nè¯·æ£æ¥:") | ||
| print(f"1. CARLAæå¡å¨æ¯å¦æ£å¨è¿è¡ (åºè¯¥è½çå°3Dçªå£)") | ||
| print(f"2. CARLAçªå£æ¯å¦å¨åå° (å°è¯ç¹å»ä¸ä¸CARLAçªå£)") | ||
| print(f"3. 妿CARLAåå¯å¨ï¼å¯è½éè¦æ´å¤æ¶é´å è½½") | ||
| return None, None | ||
|
|
||
| return None, None | ||
|
|
||
|
|
||
| # æºè½è¿æ¥ | ||
| client, world = smart_connect_to_carla() | ||
|
|
||
| if not client or not world: | ||
| print("\n" + "=" * 70) | ||
| print("è¿æ¥å¤±è´¥ï¼") | ||
| print("=" * 70) | ||
| sys.exit(1) | ||
|
|
||
| # ============================================================ | ||
| # 4. å建ç®ååºæ¯ | ||
| # ============================================================ | ||
| print("\n[4/5] åå»ºæ°æ®æ¶éåºæ¯...") | ||
|
|
||
| try: | ||
| # å建è¾åºç®å½ | ||
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | ||
| output_dir = f"cvips_data/success_{timestamp}" | ||
| os.makedirs(output_dir, exist_ok=True) | ||
|
|
||
| print(f"è¾åºç®å½: {output_dir}") | ||
|
|
||
| # ä¿åé ç½® | ||
| with open(f"{output_dir}/config.txt", "w") as f: | ||
| f.write(f"çææ¶é´: {datetime.now()}\n") | ||
| f.write(f"å°å¾: {world.get_map().name}\n") | ||
|
|
||
| # è®¾ç½®å¼æ¥æ¨¡å¼ï¼æ´ç¨³å®ï¼ | ||
| settings = world.get_settings() | ||
| settings.synchronous_mode = False | ||
| world.apply_settings(settings) | ||
|
|
||
| # 设置ç®åå¤©æ° | ||
| weather = carla.WeatherParameters( | ||
| sun_altitude_angle=90, | ||
| cloudiness=0, | ||
| precipitation=0, | ||
| fog_density=0 | ||
| ) | ||
| world.set_weather(weather) | ||
| print("â 天æ°è®¾ç½®å®æ") | ||
|
|
||
| # çæè½¦è¾ | ||
| blueprint_lib = world.get_blueprint_library() | ||
|
|
||
| # éæ©ç®åè½¦è¾ | ||
| vehicle_bp = None | ||
| vehicle_types = [ | ||
| 'vehicle.tesla.model3', | ||
| 'vehicle.audi.tt', | ||
| 'vehicle.nissan.micra', | ||
| 'vehicle.mini.cooperst' | ||
| ] | ||
|
|
||
| for vtype in vehicle_types: | ||
| if blueprint_lib.filter(vtype): | ||
| vehicle_bp = random.choice(blueprint_lib.filter(vtype)) | ||
| break | ||
|
|
||
| if not vehicle_bp: | ||
| vehicle_bp = random.choice(blueprint_lib.filter('vehicle.*')) | ||
|
|
||
| # è·åçæç¹ | ||
| spawn_points = world.get_map().get_spawn_points() | ||
| if spawn_points: | ||
| spawn_point = random.choice(spawn_points) | ||
| print(f"使ç¨çæç¹: ({spawn_point.location.x:.1f}, {spawn_point.location.y:.1f})") | ||
|
|
||
| # çæè½¦è¾ | ||
| vehicle = world.spawn_actor(vehicle_bp, spawn_point) | ||
| print(f"â çæè½¦è¾: {vehicle.type_id}") | ||
|
|
||
| # 设置èªå¨é©¾é©¶ | ||
| vehicle.set_autopilot(True) | ||
|
|
||
| # æ·»å ç®åæå头 | ||
| camera_bp = blueprint_lib.find('sensor.camera.rgb') | ||
| camera_bp.set_attribute('image_size_x', '640') | ||
| camera_bp.set_attribute('image_size_y', '480') | ||
| camera_bp.set_attribute('fov', '90') | ||
|
|
||
| # åæå头 | ||
| camera_transform = carla.Transform( | ||
| carla.Location(x=1.5, z=1.4), | ||
| carla.Rotation(pitch=0, yaw=0, roll=0) | ||
| ) | ||
| camera = world.spawn_actor(camera_bp, camera_transform, attach_to=vehicle) | ||
|
|
||
| # å¾åä¿ååè° | ||
| frame_count = [0] | ||
|
|
||
|
|
||
| def save_image(image): | ||
| frame_count[0] += 1 | ||
| if frame_count[0] <= 30: # åªä¿å30å¼ | ||
| image.save_to_disk(f"{output_dir}/frame_{frame_count[0]:03d}.png") | ||
| if frame_count[0] % 10 == 0: | ||
| print(f" å·²ä¿å {frame_count[0]}/30 帧") | ||
|
|
||
|
|
||
| camera.listen(save_image) | ||
| print("â æå头已å®è£ ") | ||
|
|
||
| # æ¶éæ°æ® | ||
| print("\n[5/5] æ¶éæ°æ® (15ç§)...") | ||
| print("æ Ctrl+C 坿åç»æ") | ||
|
|
||
| start_time = time.time() | ||
| try: | ||
| for i in range(15): | ||
| print(f" è¿åº¦: {i + 1}/15 ç§") | ||
| time.sleep(1.0) | ||
|
|
||
| print(f"\nâ æ°æ®æ¶é宿!") | ||
| print(f" æ»å¸§æ°: {frame_count[0]}") | ||
| print(f" æ°æ®ä¿åå°: {output_dir}") | ||
|
|
||
| except KeyboardInterrupt: | ||
| print(f"\næ°æ®æ¶é䏿ï¼å·²ä¿å {frame_count[0]} 帧") | ||
|
|
||
| # æ¸ ç | ||
| print("\næ¸ çåºæ¯...") | ||
| camera.stop() | ||
| camera.destroy() | ||
| vehicle.destroy() | ||
| print("â åºæ¯å·²æ¸ ç") | ||
|
|
||
| else: | ||
| print("â æ²¡ææ¾å°çæç¹ï¼è·³è¿è½¦è¾çæ") | ||
|
|
||
| except Exception as e: | ||
| print(f"â åå»ºåºæ¯æ¶åºé: {e}") | ||
| traceback.print_exc() | ||
|
|
||
| # ============================================================ | ||
| # 宿 | ||
| # ============================================================ | ||
| print("\n" + "=" * 70) | ||
| print("ð CVIPS æ°æ®çæå®æï¼") | ||
| print("=" * 70) | ||
| print(f"CARLAæå¡å¨ä»å¨è¿è¡ï¼å¯ä»¥ç»§ç»ä½¿ç¨") | ||
| print("=" * 70) | ||
|
|
||
| input("\næEnteré®éåº...") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要改成UTF-8编码,否则中文可能乱码。其他代码也是