Skip to content

Commit

Permalink
fix default file, fix camera_480p.py example
Browse files Browse the repository at this point in the history
Signed-off-by: huangziyi <[email protected]>
  • Loading branch information
MrThanlon committed Apr 10, 2024
1 parent a67428e commit feb3b66
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 55 deletions.
81 changes: 34 additions & 47 deletions share/qtcreator/examples/01-Media/camera_480p.py
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()
18 changes: 10 additions & 8 deletions src/plugins/openmv/openmvplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ void OpenMVPlugin::extensionsInitialized()
QByteArray data =
QStringLiteral("# Untitled - By: %L1 - %L2\n"
"\n"

"import sensor, image, time\n"
"\n"
"sensor.reset()\n"
Expand All @@ -1071,14 +1072,10 @@ void OpenMVPlugin::extensionsInitialized()
" clock.tick()\n"
" img = sensor.snapshot()\n"
" print(clock.fps())\n").arg(Utils::Environment::systemEnvironment().toDictionary().userName()).arg(QDate::currentDate().toString()).toUtf8();

if((m_sensorType == QStringLiteral("HM01B0")) ||
(m_sensorType == QStringLiteral("HM0360")) ||
(m_sensorType == QStringLiteral("MT9V0X2")) ||
(m_sensorType == QStringLiteral("MT9V0X4")))
{
data = data.replace(QByteArrayLiteral("sensor.set_pixformat(sensor.RGB565)"), QByteArrayLiteral("sensor.set_pixformat(sensor.GRAYSCALE)"));
if(m_sensorType == QStringLiteral("HM01B0")) data = data.replace(QByteArrayLiteral("sensor.set_framesize(sensor.VGA)"), QByteArrayLiteral("sensor.set_framesize(sensor.QVGA)"));
auto scriptPath = Core::ICore::userResourcePath(QStringLiteral("examples/01-Media/camera_480p.py")).toString();
QFile file(scriptPath);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
data = file.readAll();
}

TextEditor::BaseTextEditor *editor = qobject_cast<TextEditor::BaseTextEditor *>(Core::EditorManager::openEditorWithContents(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID, &titlePattern, data));
Expand Down Expand Up @@ -2817,6 +2814,11 @@ bool OpenMVPlugin::delayedInitialize()
" clock.tick()\n"
" img = sensor.snapshot()\n"
" print(clock.fps())\n").arg(Utils::Environment::systemEnvironment().toDictionary().userName()).arg(QDate::currentDate().toString()).toUtf8();
auto scriptPath = Core::ICore::userResourcePath(QStringLiteral("examples/01-Media/camera_480p.py")).toString();
QFile file(scriptPath);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
data = file.readAll();
}

if((m_sensorType == QStringLiteral("HM01B0")) ||
(m_sensorType == QStringLiteral("HM0360")) ||
Expand Down

0 comments on commit feb3b66

Please sign in to comment.