forked from openmv/qt-creator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix default file, fix camera_480p.py example
Signed-off-by: huangziyi <[email protected]>
- Loading branch information
Showing
2 changed files
with
44 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,69 +1,56 @@ | ||
# Camera Example | ||
|
||
from media.camera import * | ||
from media.display import * | ||
from media.media import * | ||
from time import * | ||
import time | ||
import image | ||
from mpp import * | ||
import gc | ||
from random import randint | ||
|
||
def canmv_camera_test(): | ||
print("canmv_camera_test") | ||
|
||
import time, os | ||
import sys | ||
def camera_test(): | ||
print("camera_test") | ||
# use hdmi for display | ||
display.init(LT9611_1920X1080_30FPS) | ||
|
||
# use EVB LCD for display | ||
# display.init(HX8377_1080X1920_30FPS) | ||
|
||
camera.sensor_init(CAM_DEV_ID_0, CAM_DEFAULT_SENSOR) | ||
|
||
out_width = 640 | ||
out_height = 480 | ||
# set camera out width align up with 16Bytes | ||
out_width = ALIGN_UP(out_width, 16) | ||
|
||
# set chn0 output yuv420sp | ||
# set chn0 output size | ||
camera.set_outsize(CAM_DEV_ID_0, CAM_CHN_ID_0, out_width, out_height) | ||
# set chn0 out format | ||
camera.set_outfmt(CAM_DEV_ID_0, CAM_CHN_ID_0, PIXEL_FORMAT_YUV_SEMIPLANAR_420) | ||
|
||
# create meida source device | ||
meida_source = media_device(CAMERA_MOD_ID, CAM_DEV_ID_0, CAM_CHN_ID_0) | ||
# create meida sink device | ||
meida_sink = media_device(DISPLAY_MOD_ID, DISPLAY_DEV_ID, DISPLAY_CHN_VIDEO1) | ||
# create meida link | ||
media.create_link(meida_source, meida_sink) | ||
|
||
# set display plane with video channel | ||
display.set_plane(0, 0, out_width, out_height, PIXEL_FORMAT_YVU_PLANAR_420, DISPLAY_MIRROR_NONE, DISPLAY_CHN_VIDEO1) | ||
|
||
ret = media.buffer_init() | ||
if ret: | ||
print("canmv_camera_test, buffer init failed") | ||
return ret | ||
|
||
# init meida buffer | ||
media.buffer_init() | ||
# start stream for camera device0 | ||
camera.start_stream(CAM_DEV_ID_0) | ||
img = None | ||
try: | ||
capture_count = 0 | ||
while True: | ||
img = camera.capture_image(0, 0) | ||
os.exitpoint() | ||
img = camera.capture_image(CAM_DEV_ID_0, CAM_CHN_ID_0) | ||
img.compress_for_ide() | ||
camera.release_image(0, 0, img) | ||
gc.collect() | ||
capture_count += 1 | ||
print(capture_count) | ||
except Exception as e: | ||
print(f"An error occurred during buffer used: {e}") | ||
finally: | ||
print('end') | ||
if img: | ||
camera.release_image(0, 0, img) | ||
else: | ||
print('img not dumped') | ||
# release image for dev and chn | ||
camera.release_image(CAM_DEV_ID_0, CAM_CHN_ID_0, img) | ||
except KeyboardInterrupt as e: | ||
print("user stop: ", e) | ||
except BaseException as e: | ||
sys.print_exception(e) | ||
# stop stream for camera device0 | ||
camera.stop_stream(CAM_DEV_ID_0) | ||
|
||
# deinit display | ||
display.deinit() | ||
|
||
# destroy media link | ||
media.destroy_link(meida_source, meida_sink) | ||
time.sleep(1) | ||
print("camera test exit") | ||
return 0 | ||
|
||
canmv_camera_test() | ||
os.exitpoint(os.EXITPOINT_ENABLE_SLEEP) | ||
time.sleep_ms(100) | ||
# deinit media buffer | ||
media.buffer_deinit() | ||
if __name__ == "__main__": | ||
os.exitpoint(os.EXITPOINT_ENABLE) | ||
camera_test() |
This file contains 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