Optimizing opencv 3.4 in Raspberry Pi 3 using GStreamer

Published On: May 7th, 2018
Edgar Florez Ostos
SHARE

OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library.

In this tutorial we will follow the steps to build an opencv library optimized for the raspberry pi 3 arm cortex processor with gstreamer.

These optimizations consist of building OpenCV binaries that make use of the NEON instructions and VFPV architecture.

These technologies are a great aid when dealing with large arrays of data, and SIMD instructions.

Use the following table to navigate the content, and let’s start!.

Step 1: Dependencies

Delete Wolfram Engine and LibreOffice to free 500MB ~ 1GB of disk space:

Copy to Clipboard

Update and upgrade your current packages, and install opencv dependencies:

Copy to Clipboard

# x264 Libraries

Copy to Clipboard

# GStreamer libraries

Copy to Clipboard

Step 2: Download OpenCV

Download Opencv 2.4.13.5 from https://opencv.org/releases.html

Copy to Clipboard

Step 3: Edit the compiler options

Open the file opencvcompileroptions.cmake :

Copy to Clipboard

Locate the line containing:

Copy to Clipboard

And replace it with:

Copy to Clipboard

Save the file, verify the changes made.

Step 4: Increase the swap size

Now, let’s increase the swap size so gcc can use all 4 cores of the Raspberry Pi 3.

Open the file /etc/dphys-swapfile and edit CONF_SWAPSIZE variable:

Copy to Clipboard

If you do not perform this step it’s very likely that gcc will crash when building the libraries using 4 threads.

Remember to change the swap size back to CONF_SWAPSIZE=100 once the installation is done.

WARNING: Increasing the SWAP_SIZE will reduce the lifespan of your SD card due to multiple rewrites in the flash card. Please consider doing a backup of your SD-card. Avoid using this SD-card for a final product, instead consider cloning the content of the memory into an SD-card image once your product is fully configured (with all its dependencies compiled and installed).

Restart the swapfile service:

Copy to Clipboard

Use htop to verify that the swap size increased.

Step 5: Compile and install OpenCV

Now let’s build OpenCV libraries:

Copy to Clipboard

Here comes the time consuming part, now run:

Copy to Clipboard

And wait for 2-3 hours until it finishes. Remember to check the process every now and then.

Note: using a heatsink for the processor and keeping it as cool as possible, will likely reduce the compilation time.

When (and if) OpenCV is finally compiled, install it in the linux system using:

Copy to Clipboard

Step 6: Decrease the swap size

Edit the file /etc/dphys-swapfile and change the CONF_SWAPSIZE variable:

Copy to Clipboard

Restart the swapfile service:

Copy to Clipboard

Now you can have an OpenCV built to make the best use of the processor in your Raspberry Pi 3.

Changes for OpenCV 3.1

In step 2, download OpenCV 3.1

Copy to Clipboard

In step 5, add the flag: 7

Copy to Clipboard

Custom Artificial Intelligence Solutions

We provide outsourcing services for custom AI and Computer Vision development solutions.

Artificial Intelligence

10 Comments

  1. ฝาก30รับ100 October 14, 2021 at 6:22 pm - Reply

    Blind 1 is the interior blind wound on the bottom spring roller 5 and hooked up to the higher roller 6, blind
    2 is wound on the bottom spring roller 7 and hooked up to the upper
    roller 8. The blind displacement (slit width) is achieved by persevering with to wind roller 8 after blind 1 has been totally wound.

    23 is pulled down by a spring hooked up to the highest of
    the rod and mounted to the bottom of the shutter, its progress is retarded by the pneumatic delay cylinder.

    The timing gadget sits on prime of the take-up drums.

    Because the leaf spring 29 is lowered so rod 31 is pushed
    down, the highest of 31 carries a catch 33 which can also be lowered.
    The speeds are set by moving an exterior lever which strikes
    the velocity setting rod which adjusts the circulation of air to and from the pneumatic cylinder.

  2. jasa pembuatan program kasir November 21, 2021 at 11:07 pm - Reply

    Thank you a bunch for sharing this with all of us you actually
    recognize what you are speaking about! Bookmarked. Please also discuss with my
    site =). We can have a hyperlink exchange agreement between us

    My web site … jasa pembuatan program kasir

  3. id.satthep462.com December 15, 2021 at 7:15 pm - Reply

    I don’t even know the way I ended up here,
    but I believed this put up used to be good. I don’t realize
    who you are but definitely you’re going to a famous blogger when you aren’t
    already. Cheers!

  4. Thanks on your marvelous posting! I really enjoyed reading it, you might be a great author.
    I will ensure that I bookmark your blog and will come back at
    some point. I want to encourage you to ultimately continue
    your great posts, have a nice day!

  5. Aplikasi Edit Video February 9, 2022 at 4:04 am - Reply

    This post is really a nice one it helps new the web people, who are wishing in favor of blogging.

    My web page: Aplikasi Edit Video

  6. IDN Slot February 16, 2022 at 8:06 am - Reply

    You really make it seem so easy together with
    your presentation but I to find this topic to be actually one thing which I
    think I’d never understand. It kind of feels too complex and very broad for me.
    I am having a look forward to your next put up, I
    will try to get the hang of it!

  7. jasa Desain company profile March 6, 2022 at 8:03 pm - Reply

    Thanks designed for sharing such a nice opinion, article
    is pleasant, thats why i have read it entirely

    Here is my web-site: jasa Desain company profile

  8. slot gacor March 11, 2022 at 4:09 am - Reply

    Usually I don’t read post on blogs, however I wish to say that this
    write-up very compelled me to take a look at and do it!
    Your writing taste has been amazed me. Thanks, quite
    great article.

  9. Appreciating the persistence you put into your site and detailed information you offer.
    It’s awesome to come across a blog every once in a while that isn’t the same out of date rehashed information. Wonderful read!
    I’ve bookmarked your site and I’m adding your RSS feeds to
    my Google account.

  10. Bodacious Rose Wine Review? July 16, 2022 at 5:03 am - Reply

    Do you have a spam problem on this blog; I also am a blogger,
    and I was wanting to know your situation; we have developed some
    nice methods and we are looking to trade methods with others, be sure to
    shoot me an e-mail if interested.

Leave A Comment