# Is there a port of OpenCV 3.x for FreeBSD



## leo5th (Mar 24, 2016)

Hi all,
I am a newbie of FreeBSD. I am searching for a port of OpenCV 3.0 or 3.1 for FreeBSD. I only find OpenCV 2.4.
If there is no port, how could I create a port for it?

Thanks,
Thuan


----------



## drhowarddrfine (Mar 24, 2016)

Ask the maintainer why it's not at 3.1: jhale@FreeBSD.org


----------



## leo5th (Apr 3, 2016)

Well, I could build opencv 3.1 by myself without any modification. So, I think the reason of no port of opencv is that we could build it ourselves.


----------



## jrm@ (Apr 3, 2016)

Life is easier when you install third party software as a package.  It's likely the maintainer (or anyone else) just hasn't gotten around to updating the port.  If you're feeling adventurous you can give it a shot.

https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/


----------



## Nilton Jose Rizzo (Jul 7, 2016)

leo5th said:


> Well, I could build opencv 3.1 by myself without any modification. So, I think the reason of no port of opencv is that we could build it ourselves.



Hi Leo5th, I was trying to install but i got this error and I can't resolve, you can help me?

```
% make
[  8%] Built target opencv_core
[ 18%] Built target opencv_imgproc
[ 21%] Built target opencv_imgcodecs
Scanning dependencies of target opencv_videoio
[ 21%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_libv4l.cpp.o
/usr/local/home/staff/rizzo/tmp/opencv-3.1.0/modules/videoio/src/cap_libv4l.cpp:257:10: fatal error:
  'asm/types.h' file not found
#include <asm/types.h>  /* for videodev2.h */
  ^
1 error generated.
```
I found this file in

/usr/src/sys/compat/linuxkpi/common/include/asm/types.h

But when I try to use this some other error appear, when I see a types.h code have a #define _KERNEL to create the define types s{8,16,32,64} and __s{8,16,32,64}.
I was stop because I have make many change in the code.

My system is FreeBSD 11.0 (-current) yet, last update was in December.


----------



## tobik@ (Jul 7, 2016)

Don't use /usr/src/sys/compat/linuxkpi/common/include/asm/types.h. This is for some kernel modules only.

The correct headers needed to compile software that uses V4L are in multimedia/v4l_compat. The asm/types.h include line would likely need to be removed as well. This is just a guess but it's what the current graphics/opencv port does too.


----------



## Nilton Jose Rizzo (Jul 8, 2016)

tobik said:


> Don't use /usr/src/sys/compat/linuxkpi/common/include/asm/types.h. This is for some kernel modules only.
> 
> The correct headers needed to compile software that uses V4L are in multimedia/v4l_compat. The asm/types.h include line would likely need to be removed as well. This is just a guess but it's what the current graphics/opencv port does too.




My box:

```
# uname -a
FreeBSD venus 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r293243: Thu Jan  7 00:51:45 BRST 2016  root@venus:/usr/obj/usr/src/sys/VENUS  amd64
```
the multimedia/v4l_compat already installed, but I can't found any other types.h

Solution was turn off the videoio in CMakeCache.txt

I'm not found the correct types.h to be use

```
root@venus: # pkg info -a | grep -i v4
gstreamer1-plugins-v4l2-1.6.2  GStreamer Video 4 Linux 2 source plugin
libv4l-1.6.3_1  Video4Linux library
p5-IO-Socket-IP-0.37  Drop-in replacement for IO::Socket::INET supporting IPv4 and IPv6
v4l-utils-1.6.3  Video4Linux utilities
v4l_compat-1.6.3  Video4Linux IOCTL header files

root@venus: # find  /usr/ -name types.h
/usr/include/rpc/types.h
/usr/include/sys/types.h
/usr/local/home/staff/rizzo/tmp/opencv-3.1.0/3rdparty/libwebp/webp/types.h
/usr/local/include/zzip/types.h
/usr/local/include/kpathsea/types.h
/usr/local/include/sp/types.h
/usr/local/include/webp/types.h
/usr/local/include/mutter/meta/types.h
/usr/local/include/cdio/types.h
/usr/local/include/libwmf/types.h
/usr/local/include/graphviz/types.h
/usr/local/include/libgltf-0.0/types.h
/usr/local/include/libcmis-c-0.5/libcmis-c/types.h
/usr/local/include/libopenraw-1.0/libopenraw/types.h
/usr/local/include/git2/types.h
/usr/local/include/cairomm-1.0/cairomm/types.h
/usr/local/include/pangomm-1.4/pangomm/types.h
/usr/local/include/gdkmm-3.0/gdkmm/types.h
/usr/local/include/libvcd/types.h
/usr/local/include/freerdp/types.h
/usr/local/include/wx-3.0/wx/types.h
/usr/local/include/wine/msvcrt/sys/types.h
/usr/local/include/gdkmm-2.4/gdkmm/types.h
/usr/local/include/ntfs-3g/types.h
/usr/local/include/jack/types.h
/usr/local/lib/gcc48/gcc/x86_64-portbld-freebsd11.0/4.8.5/include-fixed/sys/types.h
/usr/local/lib/gcc48/include/c++/parallel/types.h
/usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd11.0/4.7.4/include-fixed/sys/types.h
/usr/local/lib/gcc47/include/c++/parallel/types.h
/usr/local/sage-6.7/local/include/c++/4.9.2/parallel/types.h
/usr/local/sage-6.7/local/lib/gcc/x86_64-unknown-freebsd11.0/4.9.2/include-fixed/sys/types.h
/usr/src/sys/dev/isci/types.h
/usr/src/sys/compat/linuxkpi/common/include/linux/types.h
/usr/src/sys/compat/linuxkpi/common/include/asm/types.h
/usr/src/sys/sys/types.h
/usr/src/sys/cddl/compat/opensolaris/sys/types.h
/usr/src/sys/rpc/types.h
/usr/src/contrib/ofed/include/infiniband/types.h
/usr/src/contrib/sendmail/include/sm/types.h
/usr/src/contrib/ntp/lib/isc/include/isc/types.h
/usr/src/contrib/telnet/telnet/types.h
/usr/src/crypto/heimdal/appl/telnet/telnet/types.h
root@venus: #
```


----------



## tobik@ (Jul 8, 2016)

Sorry for being too vague in my previous post. I tried compiling OpenCV 3.1 myself now. You don't need asm/types.h on FreeBSD. Remove it. In patch form:

```
--- modules/videoio/src/cap_libv4l.cpp.orig	2016-07-08 20:08:26.339767464 +0200
+++ modules/videoio/src/cap_libv4l.cpp	2016-07-08 20:08:36.630757601 +0200
@@ -251,7 +251,6 @@
 #include <sys/mman.h>
 #include <string.h>
 #include <stdlib.h>
-#include <asm/types.h>          /* for videodev2.h */
 #include <assert.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
```
 There is also an issue with malloc.h:
	
	



```
--- modules/imgcodecs/src/rgbe.cpp.orig	2016-07-08 20:24:21.567695506 +0200
+++ modules/imgcodecs/src/rgbe.cpp	2016-07-08 20:24:41.556701536 +0200
@@ -44,7 +44,7 @@
 #include "rgbe.hpp"
 #include <math.h>
 #if !defined(__APPLE__)
-#include <malloc.h>
+#include <stdlib.h>
 #endif
 #include <string.h>
 #include <ctype.h>
```
To build OpenCV 3.1 with videoio:

Apply above patches
`cmake -DCMAKE_REQUIRED_INCLUDES:STRING="/usr/local/include"`
`make -j6`
I haven't tried to use it yet, but at least it compiles fine on FreeBSD 10.3/amd64.


----------



## NewGuy (Jul 9, 2016)

When I use the above patches and cmake command on the OpenCV 3.1 source, I get back an error early in the build which reports a missing header: sys/videoio.h

Anyone know which port this header belongs in?


----------



## tobik@ (Jul 9, 2016)

NewGuy said:


> Anyone know which port this header belongs in?


That header does not exist on FreeBSD (I grepped the port tree for it, no port installs it).

Is multimedia/v4l_compat (and of course multimedia/libv4l) installed? If you look at line 166 ff. in CMakeFiles/OpenCVFindLibsVideo.cmake and CMakeLists.txt (line 1040) it shouldn't try to use sys/videoio.h if it can find linux/videodev2.h.


----------



## NewGuy (Jul 10, 2016)

I do have the v4l_compat and lib4l ports installed. Also confirmed the proper include file is located in /usr/local/include/linux

I think my issue is OpenCV's configure process is not finding the files include /usr/local/include/linux, just its parent directory. Is there a flag I can pass to include additional directories of head files?


----------



## tobik@ (Jul 10, 2016)

NewGuy said:


> I think my issue is OpenCV's configure process is not finding the files include /usr/local/include/linux, just its parent directory. Is there a flag I can pass to include additional directories of head files?


That's what the -DCMAKE_REQUIRED_INCLUDES:STRING="/usr/local/include" flag does for me. If I don't add it cmake doesn't find any V4L related headers.


----------



## tobik@ (Jul 10, 2016)

Well this is all kind of silly here, because there is PR 210505.


----------



## NewGuy (Jul 10, 2016)

Guess I will just use the new port-in-testing. Cheers.


----------



## Nilton Jose Rizzo (Jul 11, 2016)

Hi All,  I was use the current port in PR, but not work, I applied some of steps indicated by tobik and work fine


----------

