In a previous blog series we have build u-boot, kernel and packages for Riotboard using Yocto.
This time we shall use the Yocto Gui based BSP and QT to create a simple camera application.
Hardware Requirements:
1. RIoTboardRIoTboard
2. LCD8000-97CLCD8000-97C (LVDS) or HDMI
3. CAM8000-DCAM8000-D
I am using LVDS display for this guide, you can use HDMI.
make sure to change boot params accordingly.
Download the BSP from here , unzip it and flash to sdcard.
Now connect the cam8000-d module to Riotboard as shown below and boot the board.
Next we shall create an App using QT to display images captured at regular intervals.
First download the qt binary webcam_demo.zip from attachment.
extract the binary from zip and copy to any location on sdcard (i copied to opt folder).
In the main window , click the List (Applications is present default) and Select All .
Next click on File Manager.
Select Opt folder and click on webcam_demo
It will open a Window & display images captured from camera (with a refresh rate of few seconds).
to capture a single snapshot (in terminal)
gst-launch mfw_v4lsrc device=/dev/video0 num-buffers=1 ! jpegenc ! filesink location=capture.jpg
The below QT code is used for this image display app.
#include <QApplication>
#include <QPushButton>
#include <QGraphicsScene>
#include <QtGui>
#include <QLabel>
#include <QPixmap>
#include <QThread>
#include <QTime>
#include <QProcess>
void delay( int millisecondsToWait )
{
QTime dieTime = QTime::currentTime().addMSecs( millisecondsToWait );
while( QTime::currentTime() < dieTime )
{
QCoreApplication::processEvents( QEventLoop::AllEvents, 100 );
}
}
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QProcess proc;
QLabel screen;
while(1)
{
QPixmap pixmap("/tmp/capture_old.jpg");
screen.setPixmap(pixmap);
screen.show();
QProcess::execute ("gst-launch mfw_v4lsrc capture-mode=0 num-buffers=1 ! jpegenc ! filesink location=/tmp/capture.jpg");
delay(1000);
QProcess::execute ("cp /tmp/capture.jpg /tmp/capture_old.jpg");
}
return app.exec();
}
Before starting make sure to setup the compilation environment .
You can find more on yocto compiler setup here .
For compilation, use the attached source file webcam_demo.cpp.zip .
Setting up directory.
mkdir webcam_demo
cd webcam_demo
download the yocto qt toolchain compiler from here.
convert it to executable.
chmod -R 777 poky-eglibc-i686-meta-toolchain-qt-cortexa9hf-vfp-neon-toolchain-qt-1.5.2.sh
Setting up compiler.
./poky-eglibc-i686-meta-toolchain-qt-cortexa9hf-vfp-neon-toolchain-qt-1.5.2.sh
Consider all defaults and proceed.
Setup environment:
source source /opt/poky/1.5.2/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
build the app:
qmake -project
qmake
make
Now the binary is ready to be executed.