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",
"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,

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()
{
/* 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 */