Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Implement OpenCV 'VideoCapture' class in 'detector.cpp' #30
Comments
jeff1evesque
changed the title from
Research C++ file structure for OpenCV
to
Implement OpenCV 'VideoCapture' class
Apr 30, 2015
jeff1evesque
changed the title from
Implement OpenCV 'VideoCapture' class
to
Implement OpenCV 'VideoCapture' class in 'detector.c'
Apr 30, 2015
added a commit
that referenced
this issue
Apr 30, 2015
|
ef2220c: we are unable to compile an implementation of the vagrant@vagrant-ubuntu-trusty-64:/vagrant$ whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/bin/X11/gcc /usr/share/man/man1/gcc.1.gz
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ls
detector.c manifests README.md Vagrantfile
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ gcc detector.c
In file included from /usr/local/include/opencv2/opencv.hpp:46:0,
from detector.c:1:
/usr/local/include/opencv2/core.hpp:47:4: error: #error core.hpp header must be compiled as C++
# error core.hpp header must be compiled as C++
^
In file included from /usr/local/include/opencv2/core.hpp:52:0,
from /usr/local/include/opencv2/opencv.hpp:46,
from detector.c:1:
/usr/local/include/opencv2/core/base.hpp:48:4: error: #error base.hpp header must be compiled as C++
# error base.hpp header must be compiled as C++
^
/usr/local/include/opencv2/core/base.hpp:51:19: fatal error: climits: No such file or directory
#include <climits>
^
compilation terminated. |
|
IRC #opencv (04/30/15 ~ 5:05pm EST):
|
added a commit
that referenced
this issue
Apr 30, 2015
|
1042664: when we rename vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ls
detector.cpp manifests README.md Vagrantfile
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ gcc detector.cpp
detector.cpp: In function ‘int main(int, char**)’:
detector.cpp:17:32: error: ‘CV_BGR2GRAY’ was not declared in this scope
cvtColor(frame, edges, CV_BGR2GRAY);
^ |
added a commit
that referenced
this issue
Apr 30, 2015
|
c767934: when we rename vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ls
detector.cxx manifests README.md Vagrantfile
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ gcc detector.cxx
detector.cxx: In function ‘int main(int, char**)’:
detector.cxx:17:32: error: ‘CV_BGR2GRAY’ was not declared in this scope
cvtColor(frame, edges, CV_BGR2GRAY);
^
|
|
The above attempted code was designed for opencv version 2.4.11.0. However, our build is 3.0.0-beta. So, we need to adjust the logic to the opencv version we are using, respectively. |
added a commit
that referenced
this issue
Apr 30, 2015
|
88f3438: we used the opencv 3.0.0-dev syntax. However, we still received the following traceback error: vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ls
detector.cxx manifests README.md Vagrantfile
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ gcc detector.cxx
/tmp/cc21xK5O.o: In function `main':
detector.cxx:(.text+0x29): undefined reference to `cv::VideoCapture::VideoCapture(int)'
detector.cxx:(.text+0x38): undefined reference to `cv::VideoCapture::isOpened() const'
detector.cxx:(.text+0x7a): undefined reference to `cv::namedWindow(cv::String const&, int)'
detector.cxx:(.text+0x99): undefined reference to `vtable for cv::VideoCapture'
detector.cxx:(.text+0xfb): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
detector.cxx:(.text+0x1b8): undefined reference to `cv::GaussianBlur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)'
detector.cxx:(.text+0x242): undefined reference to `cv::Canny(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, bool)'
detector.cxx:(.text+0x2a6): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
detector.cxx:(.text+0x2ce): undefined reference to `cv::waitKey(int)'
detector.cxx:(.text+0x31d): undefined reference to `cv::VideoCapture::~VideoCapture()'
detector.cxx:(.text+0x400): undefined reference to `cv::VideoCapture::~VideoCapture()'
/tmp/cc21xK5O.o: In function `__static_initialization_and_destruction_0(int, int)':
detector.cxx:(.text+0x43c): undefined reference to `std::ios_base::Init::Init()'
detector.cxx:(.text+0x44b): undefined reference to `std::ios_base::Init::~Init()'
/tmp/cc21xK5O.o: In function `cv::String::String(char const*)':
detector.cxx:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4f): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/cc21xK5O.o: In function `cv::String::~String()':
detector.cxx:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/cc21xK5O.o: In function `cv::_InputArray::_InputArray()':
detector.cxx:(.text._ZN2cv11_InputArrayC2Ev[_ZN2cv11_InputArrayC5Ev]+0x13): undefined reference to `vtable for cv::_InputArray'
/tmp/cc21xK5O.o: In function `cv::_InputArray::_InputArray(cv::Mat const&)':
detector.cxx:(.text._ZN2cv11_InputArrayC2ERKNS_3MatE[_ZN2cv11_InputArrayC5ERKNS_3MatE]+0x17): undefined reference to `vtable for cv::_InputArray'
/tmp/cc21xK5O.o: In function `cv::_InputArray::~_InputArray()':
detector.cxx:(.text._ZN2cv11_InputArrayD2Ev[_ZN2cv11_InputArrayD5Ev]+0x13): undefined reference to `vtable for cv::_InputArray'
detector.cxx:(.text._ZN2cv11_InputArrayD2Ev[_ZN2cv11_InputArrayD5Ev]+0x28): undefined reference to `operator delete(void*)'
/tmp/cc21xK5O.o: In function `cv::_InputArray::~_InputArray()':
detector.cxx:(.text._ZN2cv11_InputArrayD0Ev[_ZN2cv11_InputArrayD0Ev]+0x20): undefined reference to `operator delete(void*)'
/tmp/cc21xK5O.o: In function `cv::_OutputArray::_OutputArray(cv::Mat&)':
detector.cxx:(.text._ZN2cv12_OutputArrayC2ERNS_3MatE[_ZN2cv12_OutputArrayC5ERNS_3MatE]+0x23): undefined reference to `vtable for cv::_OutputArray'
/tmp/cc21xK5O.o: In function `cv::_OutputArray::~_OutputArray()':
detector.cxx:(.text._ZN2cv12_OutputArrayD2Ev[_ZN2cv12_OutputArrayD5Ev]+0x13): undefined reference to `vtable for cv::_OutputArray'
detector.cxx:(.text._ZN2cv12_OutputArrayD2Ev[_ZN2cv12_OutputArrayD5Ev]+0x34): undefined reference to `operator delete(void*)'
/tmp/cc21xK5O.o: In function `cv::_OutputArray::~_OutputArray()':
detector.cxx:(.text._ZN2cv12_OutputArrayD0Ev[_ZN2cv12_OutputArrayD0Ev]+0x20): undefined reference to `operator delete(void*)'
/tmp/cc21xK5O.o: In function `cv::Mat::~Mat()':
detector.cxx:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/cc21xK5O.o: In function `cv::Mat::release()':
detector.cxx:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
/tmp/cc21xK5O.o:(.eh_frame+0x20b): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status |
|
When we attempt to compile our vagrant@vagrant-ubuntu-trusty-64:/vagrant$ gcc detector.cxx `pkg-config --cflags --libs opencv`
/usr/bin/ld: /tmp/ccW1L4Fs.o: undefined reference to symbol '_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4'
//usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status |
|
We were able to compile vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ls
detector.cxx manifests README.md Vagrantfile
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ g++ detector.cxx `pkg-config --cflags --libs opencv`
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ls
a.out detector.cxx manifests README.md Vagrantfile |
jeff1evesque
changed the title from
Implement OpenCV 'VideoCapture' class in 'detector.c'
to
Implement OpenCV 'VideoCapture' class in 'detector.cxx'
May 1, 2015
jeff1evesque
changed the title from
Implement OpenCV 'VideoCapture' class in 'detector.cxx'
to
Implement OpenCV 'VideoCapture' class in 'detector.cpp'
May 1, 2015
added a commit
that referenced
this issue
May 1, 2015
|
Though we were able to successfully implement vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ls
detector.cpp manifests README.md Vagrantfile
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ g++ -o detector.exe detector.cpp `pkg-config --cflags --libs opencv`
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ls
detector.cpp detector.exe manifests README.md Vagrantfile
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ./detector.exe
libdc1394 error: Failed to initialize libdc1394 |
|
To resolve the above error of To keep logic contained within automated process (Vagrant), instead of simply checking the box within VirtualBox GUI, we need to install Virtualbox Extension Pack, and add the box.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--usb", "on"]
vb.customize ["modifyvm", :id, "--usbehci", "on"]
endThen, we can see that we have enabled the USB Controller: Finally, we need to define the box.vm.provider :virtualbox do |vb|
vb.customize ["usbfilter", "add", "0",
"--target", :id,
"--name", "Any mass storage",
"--manufacturer", "Generic",
"--product", "Mass Storage Device"]
endThe above code needs to adhere to the usbfilter add <index,0-N>
--target <uuid|vmname>|global
--name <string>
--action ignore|hold (global filters only)
[--active yes|no] (yes)
[--vendorid <XXXX>] (null)
[--productid <XXXX>] (null)
[--revision <IIFF>] (null)
[--manufacturer <string>] (null)
[--product <string>] (null)
[--remote yes|no] (null, VM filters only)
[--serialnumber <string>] (null)
[--maskedinterfaces <XXXXXXXX>]Now, we have USB Device Filters defined: Note: we can obtain information a list of available usb devices on the host (if needed): $ sudo VBoxManage list usbhost
[sudo] password for jeffrey:
Host USB Devices:
UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
VendorId: 0x064e (064E)
ProductId: 0xc107 (C107)
Revision: 2.49 (0249)
Port: 4
USB version/speed: 2/2
Manufacturer: SuYin
Product: xx Webcam
SerialNumber: xxxxx-xxxx-xxxx-xx-R02.43.01
Address: sysfs:/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5//device:/dev/vboxusb/002/003
Current State: Busy
UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
VendorId: 0x0781 (0781)
ProductId: 0x5575 (5575)
Revision: 1.39 (0139)
Port: 0
USB version/speed: 2/2
Manufacturer: SanDisk
Product: Cruzer Glide
SerialNumber: xxxxxxxxxxxxxxxxxxxx
Address: sysfs:/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1//device:/dev/vboxusb/001/011
Current State: Busy
|
added a commit
that referenced
this issue
May 1, 2015
added a commit
that referenced
this issue
May 1, 2015
added a commit
that referenced
this issue
May 1, 2015
added a commit
that referenced
this issue
May 1, 2015
|
Though, the above commits resolve the Also, running vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ls
detector.cpp detector.exe manifests README.md Vagrantfile
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ./detector.exe
vagrant@vagrant-ubuntu-trusty-64:/vagrant$The executable simply runs, and exits immediately, without any desired outcomes. |
This was referenced May 1, 2015
|
When we check the exit code for the last executed command, we get vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ls
detector.cpp detector.exe puppet README.md Vagrantfile
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ pico detector.cpp
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ echo $?
0
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ./detector.exe
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ echo $?
255This likely means that default camera on the host machine failed to initialize. Specifically, the following from #include "opencv2/opencv.hpp"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
... |
|
OpenCV requires the implementation of ...
sudo apt-get libavcodec-dev
sudo apt-get libavformat-dev
... |
added a commit
that referenced
this issue
May 5, 2015
|
We were able to open the Ubuntu cheese application, and it worked as expected. |
|
The above $ sudo VBoxManage list usbhost
[sudo] password for jeffrey:
Host USB Devices:
UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
VendorId: 0x064e (064E)
ProductId: 0xc107 (C107)
Revision: 2.49 (0249)
Port: 4
USB version/speed: 2/2
Manufacturer: SuYin
Product: xx Webcam
SerialNumber: xxxxx-xxxx-xxxx-xx-R02.43.01
Address: sysfs:/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5//device:/dev/vboxusb/002/003
Current State: Busy
...This means we need to define a USB Device Filter within the VirtualBox GUI. |
|
After we enabled the default camera device via the USB Device Filter on the VirtualBox GUI: We were still unable to bypass the first #include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
{
cout << "Cannot open the default webcam" << endl;
return -1;
}
...Again, we received the following output within the terminal console: vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ls
detector.cpp detector.exe puppet README.md Vagrantfile
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ./detector.exe
Cannot open the default webcam
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ echo $?
255Therefore, further logic is unable to execute since the default camera (USB) is not properly initialized with the |
|
According to the opencv 3.0 installation documentation, we can choose to either install
|
added a commit
that referenced
this issue
May 6, 2015
added a commit
that referenced
this issue
May 6, 2015
added a commit
that referenced
this issue
May 6, 2015
|
9964568, 6a09fe6: we include gstreamer to
|
added a commit
that referenced
this issue
May 6, 2015
|
We attempted the following cases with the
|
This was referenced May 7, 2015
|
We created a separate virtual environment instance, consisting of Ubuntu Server 14.04, along with the following packages:
Then, we also ensured that we Enable USB Controller on the Ubuntu Settings GUI, and defined any USB Device Filters present, without inserting any external USB devices into the host machine. However, after |
|
We need to take a look at the Virtualbox Webcam Passthrough documentation. The documentation section, discusses the possibility of the guest machine accessing the host webcam. The following shows how the jeffreys-Air:iScanner jeffrey$ VBoxManage list webcams
Video Input Devices: 1
.1 "FaceTime HD Camera"
FKH32D01XGKF9FSC7
jeffreys-Air:iScanner jeffrey$ VBoxManage list vms
"Ubuntu14.04" {ed46s6f9-cb22-4355-5555-f1bd7215ffec}
"iScanner_default_1431262003442_79804" {3fea3a26-e6aa-4324-be3f1-5frs26e6032c1}
jeffreys-Air:iScanner jeffrey$ VBoxManage controlvm "Ubuntu14.04" webcam attach FKH32D01XGKF9FSC7Note: in windows, we can install
In the case of an OSX, no USB Device Filters needed to be defined. However, the above Now, the Cheese application on the guest VM, was able to access the host webcam: |
|
This time, we connect the webcam to the target virtual machine: jeffreys-Air:iScanner jeffrey$ VBoxManage list webcams
Video Input Devices: 1
.1 "FaceTime HD Camera"
FKH32D01XGKF9FSC7
jeffreys-Air:iScanner jeffrey$ VBoxManage list vms
"Ubuntu14.04" {ed46s6f9-cb22-4355-5555-f1bd7215ffec}
"iScanner_default_1431262003442_79804" {3fea3a26-e6aa-4324-be3f1-5frs26e6032c1}
jeffreys-Air:iScanner jeffrey$ VBoxManage controlvm "iScanner_default_1431262003442_79804" webcam attach FKH32D01XGKF9FSC7However, upon jeffreys-Air:iScanner jeffrey$ cd /Users/jeffrey/github/iScanner/
jeffreys-Air:iScanner jeffrey$ ls
README.md Vagrantfile detector.cpp detector.exe puppet
jeffreys-Air:iScanner jeffrey$ vagrant up
jeffreys-Air:iScanner jeffrey$ vagrant ssh
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-52-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Mon May 11 11:03:33 UTC 2015
System load: 0.82 Processes: 85
Usage of /: 11.5% of 39.34GB Users logged in: 0
Memory usage: 24% IP address for eth0: xx.x.x.xx
Swap usage: 0%
Graph this data and manage this system at:
https://landscape.canonical.com/
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
Last login: Sun May 10 13:16:04 2015 from xx.x.x.x
vagrant@vagrant-ubuntu-trusty-64:~$ cd /vagrant
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ g++ -o detector.exe detector.cpp `pkg-config --cflags --libs opencv`
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ls
detector.cpp detector.exe puppet README.md Vagrantfile
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ./detector.exe
Cannot open the default webcam |






jeff1evesque commentedApr 30, 2015
We need to implement the
VideoCaptureclass indetector.cpp. This file will capture video from the default camera.