Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ New:
- Choose the output screen at launch with `--output-screen <name>`, by its name or its number in the list that `--list-screens` writes, then quits.
- Control the output window by OSC: `/mapmap/output/mode` (`hidden`, `window` or `screen`), `/mapmap/output/screen` (a name, or a number from 1) and `/mapmap/output/window` (`x y width height`).
- Translate MapMap into Arabic, laid out from right to left with numbers written with the digits 0 to 9, into Hindi and into Russian: choose them in Preferences > Interface > Language, or with `--lang ar`, `hi` or `ru`. No speaker of these languages has read them yet.
- See the scene from the projector, with a camera placed next to it: Tools > Auto-Mapping covers the screen of the projector with the output, projects a countdown, then black and white stripes that the camera films, about 15 seconds in all. The scene seen from the projector then shows under the shapes of the output editor, with in red what the camera did not see, to place the shapes on it by hand. Tools > Show Auto-Mapping Image hides it, Tools > Clear Auto-Mapping Image forgets it; it is never saved, and goes with the project. No image of the camera is written to the disk, unless asked with `--auto-mapping-save-images <folder>`. `--auto-mapping-simulation` films a computed scene instead, to try it without a camera or a projector. Placing shapes on the flat faces found comes in a later version.

Improvements:

Expand Down
1 change: 1 addition & 0 deletions mapmap.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ DEFINES += MAPMAP_VERSION_STRING=\\\"$$MAPMAP_VERSION\\\"

include(src/core/core.pri)
include(src/shape/shape.pri)
include(src/automap/automap.pri)
include(src/gui/gui.pri)
include(src/control/control.pri)
include(src/app/app.pri)
Expand Down
15 changes: 15 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "FrameStats.h"
#include "VideoImpl.h"
#include "MainWindow.h"
#include "AutoMappingDialog.h"
#include "OutputScreen.h"
#include "MainApplication.h"

Expand Down Expand Up @@ -230,6 +231,17 @@ int main(int argc, char *argv[])
"Write the game controllers connected, then each button pressed and each axis pushed beyond half way, until Ctrl+C. Opens no window.");
parser.addOption(listGamepadsOption);

// --auto-mapping-simulation option
QCommandLineOption autoMappingSimulationOption("auto-mapping-simulation",
"In Tools > Auto-Mapping, film a computed scene instead of a camera: to try the scan without a camera or a projector.");
parser.addOption(autoMappingSimulationOption);

// --auto-mapping-save-images option
QCommandLineOption autoMappingSaveImagesOption("auto-mapping-save-images",
"Write the images of the camera kept by Tools > Auto-Mapping, and the scene seen from the projector, to <folder>. "
"Without this option, no image of the camera is ever written.", "folder");
parser.addOption(autoMappingSaveImagesOption);

// Positional argument: file
parser.addPositionalArgument("file", "Load project from that file.");

Expand Down Expand Up @@ -365,6 +377,9 @@ int main(int argc, char *argv[])
if (parser.isSet(verboseOption))
win->setVerbose(true);

AutoMappingDialog::setSimulation(parser.isSet(autoMappingSimulationOption));
AutoMappingDialog::setImagesFolder(parser.value(autoMappingSaveImagesOption));

#ifdef HAVE_MCP
QString mcpPortValue = parser.value("mcp-port");
if (mcpPortValue != "")
Expand Down
130 changes: 130 additions & 0 deletions src/automap/AutoMapFrameSource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* AutoMapFrameSource.cpp
*
* (c) 2026 MapMap contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "AutoMapFrameSource.h"

#include <QCamera>
#include <QMediaCaptureSession>
#include <QVideoFrame>
#include <QVideoSink>
#include <QtDebug>

namespace mmp {

CameraFrameSource::CameraFrameSource(const QCameraDevice& device, QObject* parent)
: AutoMapFrameSource(parent),
_device(device)
{
}

CameraFrameSource::~CameraFrameSource()
{
stop();
}

bool CameraFrameSource::start(QString* error)
{
if (_camera)
return true;
if (_device.isNull())
{
if (error)
*error = tr("No camera is connected.");
return false;
}

_camera = new QCamera(_device, this);
_session = new QMediaCaptureSession(this);
_sink = new QVideoSink(this);
_session->setCamera(_camera);
_session->setVideoSink(_sink);
connect(_sink, &QVideoSink::videoFrameChanged, this, &CameraFrameSource::_onFrame);
connect(_camera, &QCamera::errorOccurred, this, [](QCamera::Error, const QString& message) {
qWarning() << "Auto-mapping camera:" << message;
});
_camera->start();
return true;
}

void CameraFrameSource::stop()
{
if (_camera)
_camera->stop();
delete _session;
delete _sink;
delete _camera;
_session = nullptr;
_sink = nullptr;
_camera = nullptr;
}

void CameraFrameSource::_onFrame(const QVideoFrame& frame)
{
if (!frame.isValid())
return;
const QImage image = frame.toImage();
if (!image.isNull())
emit frameReady(image.convertToFormat(QImage::Format_RGB32));
}

SimulatedFrameSource::SimulatedFrameSource(const SyntheticScene& scene, int frameInterval,
int latencyFrames, QObject* parent)
: AutoMapFrameSource(parent),
_scene(scene),
_latencyFrames(qMax(0, latencyFrames))
{
_timer.setInterval(frameInterval);
connect(&_timer, &QTimer::timeout, this, &SimulatedFrameSource::_sendFrame);
_projected = QImage(scene.outputSize(), QImage::Format_Grayscale8);
_projected.fill(Qt::black);
}

bool SimulatedFrameSource::start(QString* error)
{
Q_UNUSED(error);
_pending.clear();
_timer.start();
return true;
}

void SimulatedFrameSource::stop()
{
_timer.stop();
_pending.clear();
}

void SimulatedFrameSource::setProjectedImage(const QImage& image)
{
if (image.isNull())
{
_projected = QImage(_scene.outputSize(), QImage::Format_Grayscale8);
_projected.fill(Qt::black);
}
else
_projected = image;
}

void SimulatedFrameSource::_sendFrame()
{
_pending.enqueue(_scene.film(_projected, _frameNumber++));
if (_pending.size() > _latencyFrames)
emit frameReady(_pending.dequeue());
}

}
134 changes: 134 additions & 0 deletions src/automap/AutoMapFrameSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* AutoMapFrameSource.h
*
* (c) 2026 MapMap contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef AUTO_MAP_FRAME_SOURCE_H_
#define AUTO_MAP_FRAME_SOURCE_H_

#include "SyntheticScene.h"

#include <QCameraDevice>
#include <QImage>
#include <QObject>
#include <QQueue>
#include <QTimer>

class QCamera;
class QMediaCaptureSession;
class QVideoFrame;
class QVideoSink;

namespace mmp {

/**
* What films the scene during a scan: a real camera, or a simulated one.
*
* It sends each image as it comes, in colour. Nothing is written to the disk.
*/
class AutoMapFrameSource : public QObject
{
Q_OBJECT

public:
explicit AutoMapFrameSource(QObject* parent = nullptr) : QObject(parent) {}

/// Starts sending images. Returns false, with a message in @a error, when it cannot.
virtual bool start(QString* error) = 0;

/// Stops sending images.
virtual void stop() = 0;

/**
* Tells what the projector shows now. A real camera does not need it: it
* films the scene. A simulated camera computes what it would see.
*/
virtual void setProjectedImage(const QImage& image) { Q_UNUSED(image); }

signals:
/// A new image of the camera.
void frameReady(const QImage& frame);
};

/// A real camera, opened with Qt Multimedia.
class CameraFrameSource : public AutoMapFrameSource
{
Q_OBJECT

public:
explicit CameraFrameSource(const QCameraDevice& device, QObject* parent = nullptr);
~CameraFrameSource() override;

bool start(QString* error) override;
void stop() override;

private:
void _onFrame(const QVideoFrame& frame);

QCameraDevice _device;
QCamera* _camera = nullptr;
QMediaCaptureSession* _session = nullptr;
QVideoSink* _sink = nullptr;
};

/**
* A simulated camera that films a SyntheticScene, to try the scan without a
* camera or a projector.
*
* Like many webcams, it sends its images late: what the projector shows
* appears only after a few images.
*/
class SimulatedFrameSource : public AutoMapFrameSource
{
Q_OBJECT

public:
/// How many images late a simulated camera is, by default.
static const int DEFAULT_LATENCY_FRAMES = 3;

/// The time between two images of a simulated camera, by default: 30 images per second.
static const int DEFAULT_FRAME_INTERVAL_MS = 33;

/**
* @param scene what the camera films.
* @param frameInterval the time between two images, in milliseconds.
* @param latencyFrames how many images late it is.
*/
SimulatedFrameSource(const SyntheticScene& scene,
int frameInterval = DEFAULT_FRAME_INTERVAL_MS,
int latencyFrames = DEFAULT_LATENCY_FRAMES,
QObject* parent = nullptr);

bool start(QString* error) override;
void stop() override;
void setProjectedImage(const QImage& image) override;

private:
void _sendFrame();

SyntheticScene _scene;
int _latencyFrames;
QTimer _timer;
QImage _projected;
// The images computed but not sent yet: the latency of the camera.
QQueue<QImage> _pending;
int _frameNumber = 0;
};

}

#endif /* AUTO_MAP_FRAME_SOURCE_H_ */
Loading
Loading