treefella
Posts: 7
Joined: Thu Mar 24, 2016 11:59 pm

Pi Zero + OpenCV: Illegal instruction

Thu Apr 21, 2016 3:41 pm

Hey all,
I'm trying to get OpenCV to work on my Pi B+1.2 or Zero and on both platforms I get an "Illegal instruction" error at runtime due to OpenCV functions. I have built OpenCV from scratch on the Zero and B+ & this identical program runs just fine on both the Pi2 & Pi3.

The crash in GDB:

Code: Select all

Program received signal SIGILL, Illegal instruction.
0x0002740c in std::_Hashtable<cv::Point_<int>, std::pair<cv::Point_<int> const, tt::NoteBlob>, std::allocator<std::pair<cv::Point_<int> const, tt::NoteBlob> >, std::__detail::_Select1st, tt::cmpPoints, tt::pointHash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::_Hashtable (
    this=0xeb26c, __bucket_hint=10, __h1=..., __h2=..., __h=..., __eq=..., 
    __exk=..., __a=...) at /usr/include/c++/4.9/bits/hashtable.h:799
799	      _M_rehash_policy()
End of the disassemble dump:

Code: Select all

   0x0002745c <+244>:	ldr	r0, [r11, #-16]
   0x00027460 <+248>:	bl	0x257a4 <std::__detail::_Hashtable_alloc<std::allocator<std::__detail::_Hash_node<std::pair<cv::Point_<int> const, tt::NoteBlob>, true> > >::~_Hashtable_alloc()>
   0x00027464 <+252>:	bl	0x141b4 <_ZNSt8ios_base4InitD1Ev+564>
   0x00027468 <+256>:	mov	r0, r3
   0x0002746c <+260>:	sub	sp, r11, #4
   0x00027470 <+264>:	pop	{r11, pc}
To me, it seems its coming from a bad build of OpenCV since I get SIGILL only in lines that involve CV structures (such as cv::Point && cv::Mat).

Could someone please help me interpret this?
Ronald Sardarian
CTO @ ToneTree
tonetree.com

User avatar
scruss
Posts: 1701
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Pi Zero + OpenCV: Illegal instruction

Thu Apr 21, 2016 3:51 pm

this identical program runs just fine on both the Pi2 & Pi3
Did you accidentally build the library for the B+ and Zero using the same options as for the 2 and 3?
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
Paeryn
Posts: 2015
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Pi Zero + OpenCV: Illegal instruction

Thu Apr 21, 2016 3:54 pm

If you're getting a SIGILL only on the Zero or B and not on 2 & 3 then I'd say you configured and built OpenCV for ARMv7 rather than ARMv6.

Your disassembly doesn't help as gdb says it happened at address 0x2740c but your listing is from 0x2745c.
She who travels light — forgot something.

treefella
Posts: 7
Joined: Thu Mar 24, 2016 11:59 pm

Re: Pi Zero + OpenCV: Illegal instruction

Mon Apr 25, 2016 5:26 pm

I tried recompiling OpenCV and disabling SSE / SSE2 as suggested by some other threads but this did not help.

I looked at the address where the crash was happening and found this in the disassembly:

Code: Select all

0x00027408 <+160>:	mov	r0, r3
=> 0x0002740c <+164>:	vmov.f32	s0, #112	; 0x70
   0x00027410 <+168>:	bl	0x25150 <std::__detail::_Prime_rehash_policy::_Prime_rehash_policy(float)
I can't seem to find any suggestions on how to compile for the correct arm architecture, any suggestions?
Ronald Sardarian
CTO @ ToneTree
tonetree.com

User avatar
Paeryn
Posts: 2015
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Pi Zero + OpenCV: Illegal instruction

Mon Apr 25, 2016 11:17 pm

treefella wrote:I tried recompiling OpenCV and disabling SSE / SSE2 as suggested by some other threads but this did not help.

I looked at the address where the crash was happening and found this in the disassembly:

Code: Select all

0x00027408 <+160>:	mov	r0, r3
=> 0x0002740c <+164>:	vmov.f32	s0, #112	; 0x70
   0x00027410 <+168>:	bl	0x25150 <std::__detail::_Prime_rehash_policy::_Prime_rehash_policy(float)
I can't seem to find any suggestions on how to compile for the correct arm architecture, any suggestions?
SSE/SSE2 are intel/amd things, not ARM so you can't compile for them anyway.

vmov with an immediate value is a vfpv3 instruction, i.e. not compatible with the RPi1 / Zero which has vfpv2.
For the RPi1 / Zero the -mfpu flag needs to be -mfpu=vfp, if it says something like -mfpu=vfpv3 (or -mfpu=vfpv4 or -mfpu=neon-vfpv4 then that is the wrong value and will not work for the RPi1.

Looking at the CMakelists, there are two options that configure the fpu mode for ARM,
ENABLE_NEON "Enable NEON instructions"
ENABLE_VFPV3 "Enable VFPv3-D32 instructions"
These both need to be disabled for the RPi1
She who travels light — forgot something.

pageauc
Posts: 219
Joined: Fri Jan 04, 2013 10:52 pm

Re: Pi Zero + OpenCV: Illegal instruction

Thu Jun 07, 2018 12:50 pm

I have written a whiptail menu system for compiling opencv 3.4.1 from source.'
See GitHub https://github.com/pageauc/opencv3-setup

Quick Install
Step1 - In code box below Select All then right click copy on highlighted command.
Step2 - On a logged in RPI SSH terminal session right click paste then Enter to Run setup.sh script

Code: Select all

 curl -L https://raw.github.com/pageauc/opencv3-setup/master/setup.sh | bash 
curl comand will run the GitHub setup.sh script that will install files and configure into the ~/opencv3-setup folder.

The cv3-install.menu.sh script and menu picks will

* Validate that OPENCV_VER variable setting is correct
* Create cv3-log.txt If It Does Not Exist. The log will record system information, date/time and details of various steps including execution times
* Update/upgrade Raspbian for Raspberry Pi
* Install build dependencies
* Download opencv3 source zip files and unzip
* Auto Detect RPI3 and set NEON compile directive for cmake to enhance cv3 performance
* Run cmake to configure build
* Temporarily Increase Swap memory to 1024 MB During make
* Automatically Sets number of make cores. -j2 cores if 1 GB RAM detected, otherwise -j1 core directive is set.
* Run make to Compile opencv3 source code
* Run optional make clean to clear build directory to force full recompile.
* DELETE menu pick to optionally recover disk space by deleting the cv3-tmp folder containing opencv source and build files and folders.

Let me know what you think.
Comments are Greatly Appreciated
Claude ...
GitHub - https://github.com/pageauc
YouTube - https://www.youtube.com/user/pageaucp

Return to “Graphics programming”

Who is online

Users browsing this forum: No registered users and 2 guests