A camera problem.
-
something eluding me
To take a shotvoid Camera::takeImage()
Then on
connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, this, &Camera::processCapturedImage);
void Camera::processCapturedImage(int requestId, const QImage& img) { Q_UNUSED(requestId); QImage scaledImage = 100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); ui->lastImagePreviewLabel->setPixmap(QPixmap::fromImage(scaledImage)); // Display captured image for 4 seconds. displayCapturedImage(); QTimer::singleShot(4000, this, &Camera::displayViewfinder); }
But where the image actually stored?
-
Hi,
Unless you configure the capture to capture to file, its just going to be in the buffer. You can still save it yourself though.
-
Hi,
Unless you configure the capture to capture to file, its just going to be in the buffer. You can still save it yourself though.
@SGaist said in A camera problem.:
Hi,
Unless you configure the capture to capture to file, its just going to be in the buffer. You can still save it yourself though.
How do I do that? I see m_imageCapture but no property or method to set a path to a file.
And where the buffer located? -
The buffer just means it's in memory. You'll get a frame to process and then it's up to you to save it.
-
The buffer just means it's in memory. You'll get a frame to process and then it's up to you to save it.
@SGaist said in A camera problem.:
The buffer just means it's in memory. You'll get a frame to process and then it's up to you to save it.
After
g_camera.SetCaptureMode(QCamera::CaptureMode::CaptureStillImage); g_camera.takeImage();
Nothing happens. I didn't get to
void Camera::processCapturedImage(int requestId, const QImage& img)
or
void Camera::imageSaved(int id, const QString &fileName)
How do I know where is the image (if it was taken at all)?
-
@SGaist said in A camera problem.:
The buffer just means it's in memory. You'll get a frame to process and then it's up to you to save it.
After
g_camera.SetCaptureMode(QCamera::CaptureMode::CaptureStillImage); g_camera.takeImage();
Nothing happens. I didn't get to
void Camera::processCapturedImage(int requestId, const QImage& img)
or
void Camera::imageSaved(int id, const QString &fileName)
How do I know where is the image (if it was taken at all)?
@jenya7 Did you connect a slot to https://doc.qt.io/qt-5/qcamera.html#errorOccurred to see whether you get any errors? Same for https://doc.qt.io/qt-5/qcameraimagecapture.html#error-1
You can get the cptured image using this signal: https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable -
@jenya7 Did you connect a slot to https://doc.qt.io/qt-5/qcamera.html#errorOccurred to see whether you get any errors? Same for https://doc.qt.io/qt-5/qcameraimagecapture.html#error-1
You can get the cptured image using this signal: https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable@jsulm said in A camera problem.:
@jenya7 Did you connect a slot to https://doc.qt.io/qt-5/qcamera.html#errorOccurred to see whether you get any errors? Same for https://doc.qt.io/qt-5/qcameraimagecapture.html#error-1
You can get the cptured image using this signal: https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailablethis is what I have
connect(m_imageCapture.data(), &QCameraImageCapture::readyForCaptureChanged, this, &Camera::readyForCapture); connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, this, &Camera::processCapturedImage); connect(m_imageCapture.data(), &QCameraImageCapture::imageSaved, this, &Camera::imageSaved); connect(m_imageCapture.data(), QOverload<int, QCameraImageCapture::Error, const QString &>::of(&QCameraImageCapture::error), this, &Camera::displayCaptureError);
-
@jsulm said in A camera problem.:
@jenya7 Did you connect a slot to https://doc.qt.io/qt-5/qcamera.html#errorOccurred to see whether you get any errors? Same for https://doc.qt.io/qt-5/qcameraimagecapture.html#error-1
You can get the cptured image using this signal: https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailablethis is what I have
connect(m_imageCapture.data(), &QCameraImageCapture::readyForCaptureChanged, this, &Camera::readyForCapture); connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, this, &Camera::processCapturedImage); connect(m_imageCapture.data(), &QCameraImageCapture::imageSaved, this, &Camera::imageSaved); connect(m_imageCapture.data(), QOverload<int, QCameraImageCapture::Error, const QString &>::of(&QCameraImageCapture::error), this, &Camera::displayCaptureError);
@jenya7 So, what about trying https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable ?
-
@jenya7 So, what about trying https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable ?
@jsulm said in A camera problem.:
@jenya7 So, what about trying https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable ?
I did in Camera::setCamera
connect(m_imageCapture.data(), &QCameraImageCapture::imageAvailable, this, &Camera::ImageAvailable);
and then
void Camera::ImageAvailable(int id, const QVideoFrame &frame) { qDebug() << id; //qDebug() << frame->???; }
I also added
void Camera::displayCameraError() { //QMessageBox::warning(this, tr("Camera Error"), m_camera->errorString()); qDebug() << "Camera Error: " + m_camera->errorString() + "\n"; } void Camera::displayCaptureError(int id, const QCameraImageCapture::Error error, const QString &errorString) { Q_UNUSED(id); Q_UNUSED(error); qDebug() << "Image Capture Error: " + errorString; m_isCapturingImage = false; }
and when I do
g_camera.SetCaptureMode(QCamera::CaptureMode::CaptureStillImage); g_camera.takeImage();
I get
"Image Capture Error: Camera not ready"
How can I know a reason why the camera isn't ready?
-
@jsulm said in A camera problem.:
@jenya7 So, what about trying https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable ?
I did in Camera::setCamera
connect(m_imageCapture.data(), &QCameraImageCapture::imageAvailable, this, &Camera::ImageAvailable);
and then
void Camera::ImageAvailable(int id, const QVideoFrame &frame) { qDebug() << id; //qDebug() << frame->???; }
I also added
void Camera::displayCameraError() { //QMessageBox::warning(this, tr("Camera Error"), m_camera->errorString()); qDebug() << "Camera Error: " + m_camera->errorString() + "\n"; } void Camera::displayCaptureError(int id, const QCameraImageCapture::Error error, const QString &errorString) { Q_UNUSED(id); Q_UNUSED(error); qDebug() << "Image Capture Error: " + errorString; m_isCapturingImage = false; }
and when I do
g_camera.SetCaptureMode(QCamera::CaptureMode::CaptureStillImage); g_camera.takeImage();
I get
"Image Capture Error: Camera not ready"
How can I know a reason why the camera isn't ready?
@jenya7 Did you call
camera->setCaptureMode(QCamera::CaptureStillImage); camera->start(); //on half pressed shutter button camera->searchAndLock(); //on shutter button pressed imageCapture->capture();
like shown in https://doc.qt.io/qt-5/qcameraimagecapture.html ?
-
@jenya7 Did you call
camera->setCaptureMode(QCamera::CaptureStillImage); camera->start(); //on half pressed shutter button camera->searchAndLock(); //on shutter button pressed imageCapture->capture();
like shown in https://doc.qt.io/qt-5/qcameraimagecapture.html ?
@jsulm said in A camera problem.:
@jenya7 Did you call
camera->setCaptureMode(QCamera::CaptureStillImage); camera->start(); //on half pressed shutter button camera->searchAndLock(); //on shutter button pressed imageCapture->capture();
like shown in https://doc.qt.io/qt-5/qcameraimagecapture.html ?
I thought
void Camera::takeImage() { m_isCapturingImage = true; m_imageCapture->capture(); }
handles all this, kinda higher layer that wraps all together.
and what is
//on half pressed shutter button
//on shutter button pressed
I don't have any buttons. my app is not widget controlled. all commands issued from a command line.
I took a widget camera example (from Examples) and removed all UI related staff. -
@jsulm said in A camera problem.:
@jenya7 Did you call
camera->setCaptureMode(QCamera::CaptureStillImage); camera->start(); //on half pressed shutter button camera->searchAndLock(); //on shutter button pressed imageCapture->capture();
like shown in https://doc.qt.io/qt-5/qcameraimagecapture.html ?
I thought
void Camera::takeImage() { m_isCapturingImage = true; m_imageCapture->capture(); }
handles all this, kinda higher layer that wraps all together.
and what is
//on half pressed shutter button
//on shutter button pressed
I don't have any buttons. my app is not widget controlled. all commands issued from a command line.
I took a widget camera example (from Examples) and removed all UI related staff.@jenya7 said in A camera problem.:
I don't have any buttons.
These comments simply tell you that these methods simulate these buttons.
So, yes you have to set the capture mode, start the camera, call searchAndLock and then capture. -
@jenya7 said in A camera problem.:
I don't have any buttons.
These comments simply tell you that these methods simulate these buttons.
So, yes you have to set the capture mode, start the camera, call searchAndLock and then capture.@jsulm said in A camera problem.:
@jenya7 said in A camera problem.:
I don't have any buttons.
These comments simply tell you that these methods simulate these buttons.
So, yes you have to set the capture mode, start the camera, call searchAndLock and then capture.I changed to
void Camera::takeImage() { m_camera->start(); m_camera->searchAndLock(); m_isCapturingImage = true; m_imageCapture->capture(); }
I still have
"Image Capture Error: Camera not ready"
Do I need to set a Viewfinder?
I commented out those lines//QCameraViewfinder *v_finder = new QCameraViewfinder(); //v_finder->setFixedSize(240, 320); //v_finder->show(); //v_finder->setAttribute(Qt::WA_NoSystemBackground); //m_camera->setViewfinder(v_finder);
cause I get an exception on
QCameraViewfinder *v_finder = new QCameraViewfinder(); -
@jsulm said in A camera problem.:
@jenya7 said in A camera problem.:
I don't have any buttons.
These comments simply tell you that these methods simulate these buttons.
So, yes you have to set the capture mode, start the camera, call searchAndLock and then capture.I changed to
void Camera::takeImage() { m_camera->start(); m_camera->searchAndLock(); m_isCapturingImage = true; m_imageCapture->capture(); }
I still have
"Image Capture Error: Camera not ready"
Do I need to set a Viewfinder?
I commented out those lines//QCameraViewfinder *v_finder = new QCameraViewfinder(); //v_finder->setFixedSize(240, 320); //v_finder->show(); //v_finder->setAttribute(Qt::WA_NoSystemBackground); //m_camera->setViewfinder(v_finder);
cause I get an exception on
QCameraViewfinder *v_finder = new QCameraViewfinder(); -
@jenya7 For capturing images view finder should not be needed.
But you could try to enable it to see whether your camera works at all in Qt.
What exception do you get?@jsulm said in A camera problem.:
@jenya7 For capturing images view finder should not be needed.
But you could try to enable it to see whether your camera works at all in Qt.
What exception do you get?I get
The inferior stopped because it received a signal from the operating system.
Signal name: SIGABRT
Signal meaning: Aborted -
@jsulm said in A camera problem.:
@jenya7 For capturing images view finder should not be needed.
But you could try to enable it to see whether your camera works at all in Qt.
What exception do you get?I get
The inferior stopped because it received a signal from the operating system.
Signal name: SIGABRT
Signal meaning: Aborted -
@jenya7 Please run through debugger and post the stack trace.
Also, you should post your current code with enabled viewfinder.@jsulm said in A camera problem.:
@jenya7 Please run through debugger and post the stack trace.
Also, you should post your current code with enabled viewfinder.void Camera::setCamera(const QCameraInfo &cameraInfo) { m_camera.reset(new QCamera(cameraInfo)); connect(m_camera.data(), &QCamera::stateChanged, this, &Camera::updateCameraState); connect(m_camera.data(), QOverload<QCamera::Error>::of(&QCamera::error), this, &Camera::displayCameraError); m_mediaRecorder.reset(new QMediaRecorder(m_camera.data())); connect(m_mediaRecorder.data(), &QMediaRecorder::stateChanged, this, &Camera::updateRecorderState); m_imageCapture.reset(new QCameraImageCapture(m_camera.data())); connect(m_mediaRecorder.data(), &QMediaRecorder::durationChanged, this, &Camera::updateRecordTime); connect(m_mediaRecorder.data(), QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error), this, &Camera::displayRecorderError); m_mediaRecorder->setMetaData(QMediaMetaData::Title, QVariant(QLatin1String("Test Title"))); //connect(ui->exposureCompensation, &QAbstractSlider::valueChanged, this, &Camera::setExposureCompensation); //here the exception occurs QCameraViewfinder *v_finder = new QCameraViewfinder(); //v_finder->setFixedSize(240, 320); //v_finder->show(); v_finder->setAttribute(Qt::WA_NoSystemBackground); m_camera->setViewfinder(v_finder); updateCameraState(m_camera->state()); updateLockStatus(m_camera->lockStatus(), QCamera::UserRequest); updateRecorderState(m_mediaRecorder->state()); connect(m_imageCapture.data(), &QCameraImageCapture::readyForCaptureChanged, this, &Camera::readyForCapture); connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, this, &Camera::processCapturedImage); connect(m_imageCapture.data(), &QCameraImageCapture::imageSaved, this, &Camera::imageSaved); connect(m_imageCapture.data(), QOverload<int, QCameraImageCapture::Error, const QString &>::of(&QCameraImageCapture::error), this, &Camera::displayCaptureError); connect(m_imageCapture.data(), &QCameraImageCapture::imageAvailable, this, &Camera::ImageAvailable); connect(m_camera.data(), QOverload<QCamera::LockStatus, QCamera::LockChangeReason>::of(&QCamera::lockStatusChanged), this, &Camera::updateLockStatus); //ui->captureWidget->setTabEnabled(0, (m_camera->isCaptureModeSupported(QCamera::CaptureStillImage))); //ui->captureWidget->setTabEnabled(1, (m_camera->isCaptureModeSupported(QCamera::CaptureVideo))); updateCaptureMode(0); m_camera->start(); }
and a call stack
1 __GI_raise raise.c 50 0xb5830f14 2 __GI_abort abort.c 79 0xb581c230 3 QMessageLogger::fatal(const char *, ...) const 0xb5c1c004 4 QWidgetPrivate::QWidgetPrivate(int) 0xb698e204 5 QWidget::QWidget(QWidget *, QFlags<Qt::WindowType>) 0xb69ab42c 6 QVideoWidget::QVideoWidget(QVideoWidgetPrivate&, QWidget *) 0xb6f3ed70 7 QCameraViewfinder::QCameraViewfinder(QWidget *) 0xb6f388f4 8 Camera::setCamera camera.cpp 148 0x5a000 //this line is focused 9 Camera::Camera camera.cpp 112 0x599ec 10 __static_initialization_and_destruction_0 camera.cpp 69 0x5bd58 11 _GLOBAL__sub_I_camera.cpp(void) camera.cpp 544 0x5bdb4 12 __libc_csu_init 0xbed54 13 __libc_start_main libc-start.c 264 0xb581c6ac 14 _start
-
@jsulm said in A camera problem.:
@jenya7 Please run through debugger and post the stack trace.
Also, you should post your current code with enabled viewfinder.void Camera::setCamera(const QCameraInfo &cameraInfo) { m_camera.reset(new QCamera(cameraInfo)); connect(m_camera.data(), &QCamera::stateChanged, this, &Camera::updateCameraState); connect(m_camera.data(), QOverload<QCamera::Error>::of(&QCamera::error), this, &Camera::displayCameraError); m_mediaRecorder.reset(new QMediaRecorder(m_camera.data())); connect(m_mediaRecorder.data(), &QMediaRecorder::stateChanged, this, &Camera::updateRecorderState); m_imageCapture.reset(new QCameraImageCapture(m_camera.data())); connect(m_mediaRecorder.data(), &QMediaRecorder::durationChanged, this, &Camera::updateRecordTime); connect(m_mediaRecorder.data(), QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error), this, &Camera::displayRecorderError); m_mediaRecorder->setMetaData(QMediaMetaData::Title, QVariant(QLatin1String("Test Title"))); //connect(ui->exposureCompensation, &QAbstractSlider::valueChanged, this, &Camera::setExposureCompensation); //here the exception occurs QCameraViewfinder *v_finder = new QCameraViewfinder(); //v_finder->setFixedSize(240, 320); //v_finder->show(); v_finder->setAttribute(Qt::WA_NoSystemBackground); m_camera->setViewfinder(v_finder); updateCameraState(m_camera->state()); updateLockStatus(m_camera->lockStatus(), QCamera::UserRequest); updateRecorderState(m_mediaRecorder->state()); connect(m_imageCapture.data(), &QCameraImageCapture::readyForCaptureChanged, this, &Camera::readyForCapture); connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, this, &Camera::processCapturedImage); connect(m_imageCapture.data(), &QCameraImageCapture::imageSaved, this, &Camera::imageSaved); connect(m_imageCapture.data(), QOverload<int, QCameraImageCapture::Error, const QString &>::of(&QCameraImageCapture::error), this, &Camera::displayCaptureError); connect(m_imageCapture.data(), &QCameraImageCapture::imageAvailable, this, &Camera::ImageAvailable); connect(m_camera.data(), QOverload<QCamera::LockStatus, QCamera::LockChangeReason>::of(&QCamera::lockStatusChanged), this, &Camera::updateLockStatus); //ui->captureWidget->setTabEnabled(0, (m_camera->isCaptureModeSupported(QCamera::CaptureStillImage))); //ui->captureWidget->setTabEnabled(1, (m_camera->isCaptureModeSupported(QCamera::CaptureVideo))); updateCaptureMode(0); m_camera->start(); }
and a call stack
1 __GI_raise raise.c 50 0xb5830f14 2 __GI_abort abort.c 79 0xb581c230 3 QMessageLogger::fatal(const char *, ...) const 0xb5c1c004 4 QWidgetPrivate::QWidgetPrivate(int) 0xb698e204 5 QWidget::QWidget(QWidget *, QFlags<Qt::WindowType>) 0xb69ab42c 6 QVideoWidget::QVideoWidget(QVideoWidgetPrivate&, QWidget *) 0xb6f3ed70 7 QCameraViewfinder::QCameraViewfinder(QWidget *) 0xb6f388f4 8 Camera::setCamera camera.cpp 148 0x5a000 //this line is focused 9 Camera::Camera camera.cpp 112 0x599ec 10 __static_initialization_and_destruction_0 camera.cpp 69 0x5bd58 11 _GLOBAL__sub_I_camera.cpp(void) camera.cpp 544 0x5bdb4 12 __libc_csu_init 0xbed54 13 __libc_start_main libc-start.c 264 0xb581c6ac 14 _start
-
@jenya7 I'm confused by the code you posted: sometimes you use m_camera. and sometimes m_camera->! How can this even compile?!
Try to set a parent on QCameraViewfinder to see whether it makes a difference.
@jsulm said in A camera problem.:
@jenya7 I'm confused by the code you posted: sometimes you use m_camera. and sometimes m_camera->! How can this even compile?!
Try to set a parent on QCameraViewfinder to see whether it makes a difference.
Hmm..It's an example from the official Qt/Examples folder. I guess those with a dot - the intrinsic methods, not from a Camera class.
for example - m_camera.reset
from - C:\Qt\5.12.0\mingw73_64\include\QtCore\qscopedpointer.h -
@jsulm said in A camera problem.:
@jenya7 I'm confused by the code you posted: sometimes you use m_camera. and sometimes m_camera->! How can this even compile?!
Try to set a parent on QCameraViewfinder to see whether it makes a difference.
Hmm..It's an example from the official Qt/Examples folder. I guess those with a dot - the intrinsic methods, not from a Camera class.
for example - m_camera.reset
from - C:\Qt\5.12.0\mingw73_64\include\QtCore\qscopedpointer.h