Accessing the Android Camera in Qt
-
Hey, I consider this answered, but as a follow up does anyone have some advice on porting the qml in that example to c++? I'm looking at the advice on the Camera overview page (http://qt-project.org/doc/qt-5/cameraoverview.html), but the code snippets there aren't enough to get my app up and grabbing frames. Here's what I've got:
@int main(int argc, char *argv[])
{
QApplication a(argc, argv);QCameraViewfinder * viewFinder; QCamera * camera;
/* This did not help
QByteArray cameraDevice;
foreach(const QByteArray &deviceName, QCamera::availableDevices()) {
if (cameraDevice.isEmpty())
cameraDevice = deviceName;
}
*/camera = new QCamera(); //(cameraDevice); viewFinder = new QCameraViewfinder; camera->setViewfinder(viewFinder); viewFinder->show(); camera->start(); return a.exec();
}@
I was getting an unable to connect error. That's gone away, but I'm still just seeing a blank screen. I feel like the code above is a bit too simple, but I don't know what other steps are required.
-
try $QTPATH\Examples\Qt-5.3\multimediawidgets\camera
-
At least now I don't have to feel completely crazy...the example loads but I see no video. When I press "Record" I get an error:
W/IMediaDeathNotifier(25594): media server died
W/CameraBase(25594): Camera service died!
W/CameraBase(25594): mediaserver's remote binder Camera object died
E/Camera (25594): Error 100'Under devices I can see the front facing camera being detected and if I toggle it I get an error. When I try and re-initialize it I see
W/CameraBase(28429): An error occurred while connecting to camera: 0
D/Qt Camera(28429): Fail to connect to camera service
W/Qt (28429): thread/qthread.cpp:425 (virtual QThread::~QThread()): QThread: Destroyed while thread is still runningIt could just be my device - I've heard there are some issues with the Nexus 7 camera, and I remember reading that the Front Facing camera is labelled 1 rather than 0, so it may be that. Thank you for the help. I'll play around with this example and maybe try it on another device if I can find one.
-
try to reboot your device first.
-
Hmm, I tried rebooting twice and made sure both times that camera was the only app running. I am deploying the app from Qt creator directly using Qt version 5.3, and as far as I know the example you suggested has not been modified.
-
declarative actually worked out of the box for me, which is why I'm confused. The fairly simple QML code had no trouble finding the camera on my device, so I'm debating whether or not I should look at the source of the QML Camera object to see what's going on there.
I will also try and run the camera app on my desktop with a webcam just to verify that it works.
-
No luck on a Nexus 4...I must be doing something wrong. If I ever figure it out I'll report back.
edit: I assume nothing special needs to be done regarding Permissions in the Manifest; there is a comment in the generated file that seems to indicate Qt takes care of this based on the needs of your app.
-
https://bugreports.qt-project.org/browse/QTBUG-38942
bq. Using Qt Multimedia with QWidgets has never been really supported on Android. You'll have to stick to QML for now. We'll add support for QWidget in 5.4.0. https://codereview.qt-project.org/#change,85577 makes sure the device doesn't get into an undefined state when trying to take a picture without a valid viewport.
-
I see. Thank you very much for your help, Vincent. Perhaps I'll explore getting the VideoOutput from the QML Camera as a buffer somehow.
-
do u success?
i need it to
but i failed to convert the buffer to a QImage
[quote author="mynameisjohn" date="1401803722"]I see. Thank you very much for your help, Vincent. Perhaps I'll explore getting the VideoOutput from the QML Camera as a buffer somehow. [/quote]