<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Snap Picture Not Working]]></title><description><![CDATA[<p dir="auto">I'm trying to make a simple application that snaps a picture from the webcam, displays the picture, sends a request with the data for image recognition to a server, and displays the user's estimated age and gender. Right now, I manage to grab the picture, but it displays oddly (behind the camera stream, or just a blank space). Once I manage to resolve this, what would be the best way to get the binary data to send in a REST API request?</p>
<p dir="auto">MainWindow.h:</p>
<pre><code>namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_SnapButton_clicked();

private:
    Ui::MainWindow *ui;
    QCamera *camera;
    QCameraViewfinder *camView;
    QLabel testLabel;
};
</code></pre>
<p dir="auto">MainWindow.c</p>
<pre><code>MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);

    //qDebug() &lt;&lt; "QCameraInfo: " &lt;&lt; checkCameraAvailability();
    QList&lt;QCameraInfo&gt; cameras = QCameraInfo::availableCameras();
    camera = new QCamera(cameras.first());
    camView = new QCameraViewfinder();
    camera-&gt;setViewfinder(camView);
    camView-&gt;show();
    camera-&gt;start();

    ui-&gt;horizontalLayout-&gt;addWidget(camView);
    ui-&gt;horizontalLayout-&gt;addWidget(&amp;testLabel);
}

void MainWindow::on_SnapButton_clicked()
{
    testLabel.setPixmap(camView-&gt;grab());
}

</code></pre>
<p dir="auto">The result:<br />
<img src="https://drive.google.com/open?id=1NNUTfwmJDb98w0Bwnj75zbWMNeQ2f9nf" alt="alt text" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/topic/86620/snap-picture-not-working</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 07:03:31 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/86620.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 08 Jan 2018 19:50:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Snap Picture Not Working on Tue, 09 Jan 2018 21:07:27 GMT]]></title><description><![CDATA[<p dir="auto">If there was, it would be part of the plugin. See the <a href="http://code.qt.io/cgit/qt/qtmultimedia.git/tree/src/plugins/directshow/camera/dscamerasession.cpp#n560" target="_blank" rel="noopener noreferrer nofollow ugc">DSCameraSession class</a>.</p>
]]></description><link>https://forum.qt.io/post/435735</link><guid isPermaLink="true">https://forum.qt.io/post/435735</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 09 Jan 2018 21:07:27 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Tue, 09 Jan 2018 21:02:47 GMT]]></title><description><![CDATA[<p dir="auto">Is there a file I can download that implements it for Windows, or is this a problem of QT having to get around to it?</p>
]]></description><link>https://forum.qt.io/post/435733</link><guid isPermaLink="true">https://forum.qt.io/post/435733</guid><dc:creator><![CDATA[Trayon]]></dc:creator><pubDate>Tue, 09 Jan 2018 21:02:47 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Tue, 09 Jan 2018 20:51:48 GMT]]></title><description><![CDATA[<p dir="auto">Because the windows platform camera plugin doesn't implement that option.</p>
]]></description><link>https://forum.qt.io/post/435726</link><guid isPermaLink="true">https://forum.qt.io/post/435726</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 09 Jan 2018 20:51:48 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Tue, 09 Jan 2018 20:48:17 GMT]]></title><description><![CDATA[<p dir="auto">Apparently it works on Linux but not Windows. Anybody have some insight as to why?</p>
]]></description><link>https://forum.qt.io/post/435724</link><guid isPermaLink="true">https://forum.qt.io/post/435724</guid><dc:creator><![CDATA[Trayon]]></dc:creator><pubDate>Tue, 09 Jan 2018 20:48:17 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Tue, 09 Jan 2018 20:38:26 GMT]]></title><description><![CDATA[<p dir="auto">I looked into using the QImage, but I would either have to convert it to a QVideoFrame (and I couldn't find how), or perform a tedious manual conversion. I'd rather find out why the buffer option isn't supported and fix it rather than hack my way around. I'm going to try on my Linux machine with a spare webacam I found and see if that works.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
I don't see why a temporary image would fare better than a buffer. I would have to read the file and re-fill my buffer if it fails, resulting in more time lost.</p>
]]></description><link>https://forum.qt.io/post/435719</link><guid isPermaLink="true">https://forum.qt.io/post/435719</guid><dc:creator><![CDATA[Trayon]]></dc:creator><pubDate>Tue, 09 Jan 2018 20:38:26 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Tue, 09 Jan 2018 20:25:08 GMT]]></title><description><![CDATA[<p dir="auto">Since you want to send it to a REST service, why not exploit the fact that having that temporary file allows you to retry a failed upload without clogging the memory used by your application. You can delete the file once you're done with it.</p>
]]></description><link>https://forum.qt.io/post/435713</link><guid isPermaLink="true">https://forum.qt.io/post/435713</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 09 Jan 2018 20:25:08 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Tue, 09 Jan 2018 20:24:34 GMT]]></title><description><![CDATA[<p dir="auto">Did you try connecting the imageCaptured signal (forgive the old syntax) ?</p>
<pre><code>connect(m_pImageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(processCapturedImage(int,QImage)));
</code></pre>
<p dir="auto">Then the slot:<br />
void xxxxx::processCapturedImage(int requestId, const QImage&amp; img)</p>
<p dir="auto">You can extract from the QImage passed to the slot.</p>
]]></description><link>https://forum.qt.io/post/435712</link><guid isPermaLink="true">https://forum.qt.io/post/435712</guid><dc:creator><![CDATA[mranger90]]></dc:creator><pubDate>Tue, 09 Jan 2018 20:24:34 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Tue, 09 Jan 2018 20:18:11 GMT]]></title><description><![CDATA[<p dir="auto">Actually, inspired by your post, I looked at isCaptureDestinationSupported. Apparently a buffer is not supported... Does anyone know why this could be?</p>
]]></description><link>https://forum.qt.io/post/435710</link><guid isPermaLink="true">https://forum.qt.io/post/435710</guid><dc:creator><![CDATA[Trayon]]></dc:creator><pubDate>Tue, 09 Jan 2018 20:18:11 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Tue, 09 Jan 2018 20:12:00 GMT]]></title><description><![CDATA[<p dir="auto">My code set that value already. You can see it in the last function definition 'on_SnapButton_clicked()'</p>
]]></description><link>https://forum.qt.io/post/435709</link><guid isPermaLink="true">https://forum.qt.io/post/435709</guid><dc:creator><![CDATA[Trayon]]></dc:creator><pubDate>Tue, 09 Jan 2018 20:12:00 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Tue, 09 Jan 2018 19:52:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/trayon">@<bdi>Trayon</bdi></a><br />
<a href="http://doc.qt.io/qt-5/qcameraimagecapture.html#CaptureDestination-enum" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qcameraimagecapture.html#CaptureDestination-enum</a></p>
<p dir="auto">?</p>
]]></description><link>https://forum.qt.io/post/435704</link><guid isPermaLink="true">https://forum.qt.io/post/435704</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 09 Jan 2018 19:52:30 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Tue, 09 Jan 2018 19:48:16 GMT]]></title><description><![CDATA[<p dir="auto">I looked around and read that "imageCapture-&gt;capture();" will only capture to a file (and filled up my picture directory). I haven't found any way to trigger a capture to buffer. Can anyone help?</p>
]]></description><link>https://forum.qt.io/post/435702</link><guid isPermaLink="true">https://forum.qt.io/post/435702</guid><dc:creator><![CDATA[Trayon]]></dc:creator><pubDate>Tue, 09 Jan 2018 19:48:16 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Mon, 08 Jan 2018 22:39:11 GMT]]></title><description><![CDATA[<p dir="auto">I'm aware of that class, I just wanted to prototype with the easy way before messing with anything more complicated. If you could give me insight as to why my initial approach doesn't work, I'd appreciate it. In the mean time, I've also tried to start doing this the "right way", but alas ran into trouble rather fast. I connected the image capture to my class for when I snap a photo, but it's not getting into the function (which prints a simple id through qDebug). Here's my code:</p>
<p dir="auto">MainWindow.c:</p>
<pre><code>MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);

    //qDebug() &lt;&lt; "QCameraInfo: " &lt;&lt; checkCameraAvailability();
    QList&lt;QCameraInfo&gt; cameras = QCameraInfo::availableCameras();
    camera = new QCamera(cameras.first());
    imageCapture = new QCameraImageCapture(camera);

    connect(imageCapture,&amp;QCameraImageCapture::imageAvailable,this,&amp;MainWindow::testFunc);

    camView = new QCameraViewfinder();
    camera-&gt;setViewfinder(camView);
    camView-&gt;show();
    camera-&gt;start();

    ui-&gt;horizontalLayout-&gt;addWidget(camView);
    ui-&gt;horizontalLayout-&gt;addWidget(&amp;testLabel);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::testFunc(int id, QVideoFrame buffer)
{
    qDebug() &lt;&lt; id;
}

void MainWindow::on_SnapButton_clicked()
{
    imageCapture-&gt;setCaptureDestination(QCameraImageCapture::CaptureToBuffer);
    imageCapture-&gt;setBufferFormat(QVideoFrame::Format_Jpeg);

    camera-&gt;setCaptureMode(QCamera::CaptureStillImage);

    camera-&gt;searchAndLock();
    imageCapture-&gt;capture();
    camera-&gt;unlock();
    //testLabel.setPixmap(camView-&gt;grab());
}
</code></pre>
]]></description><link>https://forum.qt.io/post/435491</link><guid isPermaLink="true">https://forum.qt.io/post/435491</guid><dc:creator><![CDATA[Trayon]]></dc:creator><pubDate>Mon, 08 Jan 2018 22:39:11 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Mon, 08 Jan 2018 20:16:36 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I think you should take a look at the <a href="http://doc.qt.io/qt-5/qcameraimagecapture.html" target="_blank" rel="noopener noreferrer nofollow ugc">QCameraImageCapture class</a>.</p>
]]></description><link>https://forum.qt.io/post/435437</link><guid isPermaLink="true">https://forum.qt.io/post/435437</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 08 Jan 2018 20:16:36 GMT</pubDate></item><item><title><![CDATA[Reply to Snap Picture Not Working on Mon, 08 Jan 2018 19:58:17 GMT]]></title><description><![CDATA[<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/38972eea-c556-4e7e-bba5-ee6fae1dd925.jpg" alt="0_1515441490517_Result.jpg" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/435431</link><guid isPermaLink="true">https://forum.qt.io/post/435431</guid><dc:creator><![CDATA[Trayon]]></dc:creator><pubDate>Mon, 08 Jan 2018 19:58:17 GMT</pubDate></item></channel></rss>