OpenCV on Raspberry Pi

Well then it's time to do some useful stuff with the raspberry Pi, let's install opencv on it and try to show picture.


First you want to do is to install opencv

pacman -S opencv opencv-samples

opencv-samples are not mandatory, but they can get useful.

After opencv installs, let's write a sample c++ code to open an image from file and then apply basic thresholding

#include <cv.h>
#include <ml.h>
#include <cxcore.h>
#include <highgui.h>
 
using namespace cv;
using namespace std;
 
#define THRESH_VALUE 200
#define THRESH_MODE 0
#define THRESH_MAX_VALUE 255
 
int main()
{
    Mat original_image = imread("GreenApple.jpg");
    Mat thresh_img;
 
    //Show original image
    imshow("Original", original_image);
 
    //convert the image to gray
    cvtColor( original_image, thresh_img, CV_RGB2GRAY );
 
    //Threshold the image
    threshold( thresh_img, thresh_img, THRESH_VALUE, THRESH_MAX_VALUE, THRESH_MODE );
 
    //lets show the output
    imshow("Thresholded", thresh_img);
 
    //Wait until any key is pressed
    waitKey(0);
    cout << "Exiting application\n";
 
    return 0;
}

 

To compile you will need base-devel package isntalled on your system

pacman -S base-devel

Before compiling let's check if everything is good to go with the opencv library

pkg-config opencv --libs

That should show bunch of paths to opencv library.

 

Then we can safely compile the opencv C++ application

g++ -g -Wall -o opencv_test opencv_test.cpp `pkg-config opencv --libs --cflags`

Then just run your application, like normally on linux machine

./opencv_test

 

Here is the original picture and thresholded picture, and it was all done by raspberry Pi:



Related Articles



ADVERTISEMENT

  • Chris Sparks

    Chris Sparks in Simple TLS/SSL SMTP client for Qt5

    qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed

    Edward Martin

    Edward Martin in Introduction to data encryption

    The introduction to the data encryption is very much helpful as you will get to know about the data encryption procedure which might help you to protect the files and folders. You can check the 

    bean

    bean in DIY 3D printer, AKA RepRap

    The 3D printer creates the dimensional object and with the features of the 3D printer, it executes the process if need further query then visit fix error code 0xc004f074...

    preter jack

    preter jack in Single Cycle MIPS CPU in VHDL

    Single-cycle CPU is more improved than the normal and usual CPUs and it has a lot of advantages and all you can get from fix

    henrydevid

    henrydevid in nRF51 Makefile with Qt Creator

    It is great for all, I have some different tricks if you want to know it then for that I have some different tricks, for that, you want to learn to code. For that, if you want to know it then for that you just visit some tutorial. And from there it is great for all. If you faced any type...

    Steve Rogger

    Steve Rogger in OpenCV on Raspberry Pi

    I have read the post and it is very much helpful because I have got to know about the open cv on the raspberry pi. The images and the screenshots provided here will guide you for your questions. The code you will get here is very unique and can be only used to run OpenCV. If you face any...

    preter jack

    preter jack in Programming micro-controller (Arduino) with cheap HC-06 Bluetooth

    This type of IC Bluetooth offers a lot of advantages and this type of Bluetooth are really very user-friendly and easy to use. It provides many unique features that are all mentioned over the