From d8c5bdd56d18115c1e3f8badb80431d050fda71a Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 10 Aug 2022 13:44:59 -0400 Subject: [PATCH] try to set a requested camera resolution --- config.json | 13 ++++++++++++- lib/sb | 2 +- src/Pudding.cpp | 21 ++++++++++++++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/config.json b/config.json index fb7e4a7..cbae764 100644 --- a/config.json +++ b/config.json @@ -6,12 +6,15 @@ "title": "Pudding", "debug": false, "render driver": "opengl", - "show-cursor": true + "show-cursor": true, + "camera-resolution": [1280, 720] }, + "configuration": { "auto-refresh": true }, + "keys": { "print-video-memory-size": ["CTRL", "v"], @@ -21,6 +24,7 @@ "effect": ["CTRL", "e"], "tile": ["CTRL", "t"] }, + "recording": { "screenshot-directory": "local/screenshots", @@ -31,11 +35,13 @@ "max-video-memory": 2000, "mp4-pixel-format": "yuv420p" }, + "input": { "any-key-ignore-commands": ["up", "right", "down", "left"], "suppress-any-key-on-mods": true }, + "log": { "enabled": true, @@ -45,6 +51,7 @@ "info-file-name": "gunkiss_info.log", "debug-file-name": "gunkiss_debug.log" }, + "scan": { "enabled": true, @@ -53,6 +60,7 @@ "barcode": "0140231056", "capture-device": "/dev/video0" }, + "api": { "user-agent": "Custom pudding creation game for http://nugget.fun", @@ -69,6 +77,7 @@ "best-buy-enabled": true, "google-books-enabled": true }, + "pudding": { "rotation-speed": 0.005, @@ -79,11 +88,13 @@ "y-range": [-0.6, 0.6], "gradient-position": 0.25 }, + "resource": { "tile-path": "resource/tile", "button-path": "resource/button" }, + "interface": { "main-button-y": -0.75, diff --git a/lib/sb b/lib/sb index dc2141c..0bf2e12 160000 --- a/lib/sb +++ b/lib/sb @@ -1 +1 @@ -Subproject commit dc2141c2c441d92b35979f3dac0d5d7e74e440d6 +Subproject commit 0bf2e1293542da180a325455610a72df5697853d diff --git a/src/Pudding.cpp b/src/Pudding.cpp index 0e76d4c..ad0a2dc 100644 --- a/src/Pudding.cpp +++ b/src/Pudding.cpp @@ -277,17 +277,32 @@ void Pudding::load_pads() */ void Pudding::initialize_camera() { - /* Open the OpenCV capture and assign device ID 0 for getting images from the default attached camera. */ + /* Open the OpenCV capture, using device ID #0 to get the default attached camera. */ int device_id = 0; capture.open(device_id); std::ostringstream message; if (capture.isOpened()) { - message << "opened and initialized " << capture.get(cv::CAP_PROP_FRAME_WIDTH) << "x" << + message << "Opened and initialized " << capture.get(cv::CAP_PROP_FRAME_WIDTH) << "x" << capture.get(cv::CAP_PROP_FRAME_HEIGHT) << ", " << capture.get(cv::CAP_PROP_FPS) << "fps video capture device ID #" << device_id << " using " << capture.getBackendName(); - /* Use the texture object to generate a texture the size of the camera's resolution. */ + /* Check config for a requested camera resolution, and if there is one, try applying it to the `cv::VideoCapture`. The + * requested resolution may not be available, and if so, `cv::VideoCapture` will choose a resolution. If the resulting + * resolution is different from the config value, print the resolution the capture device was set to instead. */ + if (configuration()["display"].contains("camera-resolution")) + { + capture.set(cv::CAP_PROP_FRAME_WIDTH, configuration()["display"]["camera-resolution"][0]); + capture.set(cv::CAP_PROP_FRAME_HEIGHT, configuration()["display"]["camera-resolution"][1]); + message << std::endl << "Changed resolution to " << configuration()["display"]["camera-resolution"]; + if (capture.get(cv::CAP_PROP_FRAME_WIDTH) != configuration()["display"]["camera-resolution"][0] || + capture.get(cv::CAP_PROP_FRAME_HEIGHT) != configuration()["display"]["camera-resolution"][1]) + { + message << " (but got " << capture.get(cv::CAP_PROP_FRAME_WIDTH) << "x" << capture.get(cv::CAP_PROP_FRAME_HEIGHT) << ")"; + } + } + + /* Generate a texture the size of the camera's resolution. */ camera_view.texture().generate({capture.get(cv::CAP_PROP_FRAME_WIDTH), capture.get(cv::CAP_PROP_FRAME_HEIGHT)}); /* Create and detach a thread which will read frame data */