try to set a requested camera resolution

This commit is contained in:
ohsqueezy 2022-08-10 13:44:59 -04:00
parent 7ff0d01c6f
commit d8c5bdd56d
3 changed files with 31 additions and 5 deletions

View File

@ -6,12 +6,15 @@
"title": "Pudding", "title": "Pudding",
"debug": false, "debug": false,
"render driver": "opengl", "render driver": "opengl",
"show-cursor": true "show-cursor": true,
"camera-resolution": [1280, 720]
}, },
"configuration": "configuration":
{ {
"auto-refresh": true "auto-refresh": true
}, },
"keys": "keys":
{ {
"print-video-memory-size": ["CTRL", "v"], "print-video-memory-size": ["CTRL", "v"],
@ -21,6 +24,7 @@
"effect": ["CTRL", "e"], "effect": ["CTRL", "e"],
"tile": ["CTRL", "t"] "tile": ["CTRL", "t"]
}, },
"recording": "recording":
{ {
"screenshot-directory": "local/screenshots", "screenshot-directory": "local/screenshots",
@ -31,11 +35,13 @@
"max-video-memory": 2000, "max-video-memory": 2000,
"mp4-pixel-format": "yuv420p" "mp4-pixel-format": "yuv420p"
}, },
"input": "input":
{ {
"any-key-ignore-commands": ["up", "right", "down", "left"], "any-key-ignore-commands": ["up", "right", "down", "left"],
"suppress-any-key-on-mods": true "suppress-any-key-on-mods": true
}, },
"log": "log":
{ {
"enabled": true, "enabled": true,
@ -45,6 +51,7 @@
"info-file-name": "gunkiss_info.log", "info-file-name": "gunkiss_info.log",
"debug-file-name": "gunkiss_debug.log" "debug-file-name": "gunkiss_debug.log"
}, },
"scan": "scan":
{ {
"enabled": true, "enabled": true,
@ -53,6 +60,7 @@
"barcode": "0140231056", "barcode": "0140231056",
"capture-device": "/dev/video0" "capture-device": "/dev/video0"
}, },
"api": "api":
{ {
"user-agent": "Custom pudding creation game for http://nugget.fun", "user-agent": "Custom pudding creation game for http://nugget.fun",
@ -69,6 +77,7 @@
"best-buy-enabled": true, "best-buy-enabled": true,
"google-books-enabled": true "google-books-enabled": true
}, },
"pudding": "pudding":
{ {
"rotation-speed": 0.005, "rotation-speed": 0.005,
@ -79,11 +88,13 @@
"y-range": [-0.6, 0.6], "y-range": [-0.6, 0.6],
"gradient-position": 0.25 "gradient-position": 0.25
}, },
"resource": "resource":
{ {
"tile-path": "resource/tile", "tile-path": "resource/tile",
"button-path": "resource/button" "button-path": "resource/button"
}, },
"interface": "interface":
{ {
"main-button-y": -0.75, "main-button-y": -0.75,

2
lib/sb

@ -1 +1 @@
Subproject commit dc2141c2c441d92b35979f3dac0d5d7e74e440d6 Subproject commit 0bf2e1293542da180a325455610a72df5697853d

View File

@ -277,17 +277,32 @@ void Pudding::load_pads()
*/ */
void Pudding::initialize_camera() 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; int device_id = 0;
capture.open(device_id); capture.open(device_id);
std::ostringstream message; std::ostringstream message;
if (capture.isOpened()) 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) << capture.get(cv::CAP_PROP_FRAME_HEIGHT) << ", " << capture.get(cv::CAP_PROP_FPS) <<
"fps video capture device ID #" << device_id << " using " << capture.getBackendName(); "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)}); 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 */ /* Create and detach a thread which will read frame data */