Opencv functions was not declared - opencv3.0

I switched to new opencv 3.0 as it is newer and has more function, but I faced with a problem.
When I compile old code which was perfectly working on version 2.4.8, it could not find some function:
error: ‘resize’ was not declared in this scope
error: ‘VideoCapture’ was not declared in this scope
error: ‘namedWindow’ was not declared in this scope
error: ‘cvtColor’ was not declared in this scope
error: ‘imshow’ was not declared in this scope
error: ‘Sobel’ was not declared in this scope
here the small piece of code as an example:
test.cpp:
#include <opencv/highgui.h>
#include <opencv/cv.h>
using namespace cv;
int main( int argc, char** argv )
{
IplImage* imgX;
IplImage* img = cvLoadImage( argv[1] );
Sobel(img, imgX, CV_32F, 1, 0, 1);
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", imgX );
cvWaitKey(0);
cvReleaseImage( &imgX );
cvDestroyWindow("Example1");
}
CMakeList.txt:
cmake_minimum_required (VERSION 2.6)
project (Test)
find_package( OpenCV REQUIRED )
add_executable(Test test.cpp)
target_link_libraries( Test ${OpenCV_LIBS} )
and output:
Scanning dependencies of target Test
[100%] Building CXX object CMakeFiles/Test.dir/test.cpp.o
/home/kairat/Dropbox/ComputerVision/Codes/test/test.cpp: In function ‘int main(int, char**)’:
/home/kairat/Dropbox/ComputerVision/Codes/test/test.cpp:11:34: error: ‘Sobel’ was not declared in this scope
Sobel(img, imgX, CV_32F, 1, 0, 1);
^
CMakeFiles/Test.dir/build.make:54: recipe for target 'CMakeFiles/Test.dir/test.cpp.o' failed
make[2]: *** [CMakeFiles/Test.dir/test.cpp.o] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/Test.dir/all' failed
make[1]: *** [CMakeFiles/Test.dir/all] Error 2
Makefile:75: recipe for target 'all' failed
make: *** [all] Error 2
What I could do in this situation?

Sobel(img, imgX, CV_32F, 1, 0, 1); this is c++ version of sobel function.
you should use c version of sobel function
i.e cvSobel(img, imgX,1, 0, 1); as you are dealing with C structure IPLimage.
Note:C version of opencv functions generally starts with "cv".
Otherwise convert your IPLimages to Mats using this function
Mat src = cvarrToMat(img) then use Sobel(src , srcX, CV_32F, 1, 0, 1);
it is recommended to use the c++ functions by dealing with Mats which has more advantages like automatic memory allocation/reallocation for outputs and automatic memory releasing.

Related

Error while building a static Linux binary (with musl-libc) that includes LuaJIT

I've cloned the LuaJIT git repo and built it with:
make STATIC_CC="musl-gcc" BUILDMODE="static"
Then, I compiled a simple Lua "hello world" script into a C header file:
luajit -b test.lua test.h
test.h:
#define luaJIT_BC_test_SIZE 52
static const unsigned char luaJIT_BC_test[] = {
27,76,74,2,10,45,2,0,3,0,2,0,4,54,0,0,0,39,2,1,0,66,0,2,1,75,0,1,0,20,72,101,
108,108,111,32,102,114,111,109,32,76,117,97,33,10,112,114,105,110,116,0
};
After that, I wrote a simple C wrapper by following the official example, test.c:
#include <stdio.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "test.h"
int main(void) {
int error;
lua_State *L = lua_open();
luaL_openlibs(L);
error = luaL_loadbuffer(L, (const char *) luaJIT_BC_test, luaJIT_BC_test_SIZE, "test") || lua_pcall(L, 0, 0, 0);
if (error) {
fprintf(stderr, "%s", lua_tostring(L, -1));
lua_pop(L, 1);
}
lua_close(L);
return 0;
}
But when I try to build it, it crashes with an error:
$ musl-gcc -static -ILuaJIT/src -LLuaJIT/src -o test test.c -lluajit
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/libgcc_eh.a(unwind-dw2-fde-dip.o): in function `_Unwind_Find_FDE':
(.text+0x1953): undefined reference to `_dl_find_object'
collect2: error: ld returned 1 exit status
It's related to libgcc, so I tried building everything with musl-clang, but still got the same error. Can someone explain what I'm missing here?
Figured it out - I needed to build LuaJIT with TARGET_XCFLAGS=-DLUAJIT_NO_UNWIND like so:
make STATIC_CC="musl-gcc" BUILDMODE="static" TARGET_XCFLAGS=-DLUAJIT_NO_UNWIND
I guess this just disables C++ exceptions support, but I'm not sure what the real implications are. Seems to work fine, for now.

gem install mongoid --platform=ruby failed to build gem native extension

i 'm using windows 7 and when i try to install mongoid i have this problem this is the log
C:/Ruby200/bin/ruby.exe -r ./siteconf20140806-7376-tm3b3l.rb extconf.rb
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
generating native-i386-mingw32.def
compiling native.c
In file included from c:/Ruby200/include/ruby-2.0.0/ruby/defines.h:153:0,
from c:/Ruby200/include/ruby-2.0.0/ruby/ruby.h:70,
from c:/Ruby200/include/ruby-2.0.0/ruby.h:33,
from native.c:26:
c:/Ruby200/include/ruby-2.0.0/ruby/win32.h: In function 'rb_w32_pow':
c:/Ruby200/include/ruby-2.0.0/ruby/win32.h:801:5: warning: implicit declaration of
function '_controlfp' [-Wimplicit-function-declaration]
c:/Ruby200/include/ruby-2.0.0/ruby/win32.h:802:16: error: '_PC_64' undeclared (first
use in this function)
c:/Ruby200/include/ruby-2.0.0/ruby/win32.h:802:16: note: each undeclared identifier is
reported only once for each function it appears in c:/Ruby200/include/ruby-
2.0.0/ruby/win32.h:802:24: error: '_MCW_PC' undeclared (first use in this function)
make: *** [native.o] Error 1
make failed, exit code 2
i have installed devKit
I just had the same issues and this link https://github.com/mongoid/mongoid/issues/3489 helped me solve the problem.
So first, go to your ...\Ruby200\include\ruby-2.0.0\ruby directory and locate win32.h file.
Then modify the file by adding the missing variables:
...
...
static inline double
rb_w32_pow(double x, double y)
{
return powl(x, y);
}
#elif defined(__MINGW64_VERSION_MAJOR)
#ifndef _PC_64
#define _PC_64 0x00000000
#endif
#ifndef _MCW_PC
#define _MCW_PC 0x00030000
#endif
/*
* Set floating point precision for pow() of mingw-w64 x86.
* With default precision the result is not proper on WinXP.
*/
static inline double
rb_w32_pow(double x, double y)
{
double r;
unsigned int default_control = _controlfp(0, 0);
_controlfp(_PC_64, _MCW_PC);
r = pow(x, y);
/* Restore setting */
_controlfp(default_control, _MCW_PC);
return r;
}
...
...
Hope it works for you as well! Good luck!

Linker issue in opencv

I am using OpenCV 2.4.6 in Visual Studio 2012 and I have testing one of the sample programs , name matcher_simple.cpp -- which matches two sample images , image1 and image2.
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/opencv.hpp"
using namespace cv;
static void help()
{
printf("\nThis program demonstrates using features2d detector, descriptor extractor and simple matcher\n"
"Using the SURF desriptor:\n"
"\n"
"Usage:\n matcher_simple <image1> <image2>\n");
}
int main(int argc, char** argv)
{
if(argc != 3)
{
help();
return -1;
}
//cv::initModule_nonfree();
Mat img1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
Mat img2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
if(img1.empty() || img2.empty())
{
printf("Can't read one of the images\n");
return -1;
}
// detecting keypoints
SurfFeatureDetector detector(400);
vector<KeyPoint> keypoints1, keypoints2;
detector.detect(img1, keypoints1);
detector.detect(img2, keypoints2);
// computing descriptors
SurfDescriptorExtractor extractor;
Mat descriptors1, descriptors2;
extractor.compute(img1, keypoints1, descriptors1);
extractor.compute(img2, keypoints2, descriptors2);
// matching descriptors
BFMatcher matcher(NORM_L2);
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);
// drawing the results
namedWindow("matches", 1);
Mat img_matches;
drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
imshow("matches", img_matches);
waitKey(0);
return 0;
}
On compiling I get this error :
1>------ Build started: Project: opencvreinstated, Configuration: Release x64 ------
1>matcher_simple.obj : error LNK2001: unresolved external symbol "public: __cdecl cv::SURF::SURF(void)" (??0SURF#cv##QEAA#XZ)
1>matcher_simple.obj : error LNK2001: unresolved external symbol "public: __cdecl cv::SURF::SURF(double,int,int,bool,bool)" (??0SURF#cv##QEAA#NHH_N0#Z)
1>C:\Users\motiur\documents\visual studio 2012\Projects\opencvreinstated\x64\Release\opencvreinstated.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have testing this in release mode 64 bit , I also have successfully ran simple other opencv samples , for example streaming live video . I did not have these sort of issues there . Help is appreciated . Thanks.
You have to link in the nonfree module, since this is where the Surf features are implemented.
Go to project Properties -> Linker -> Input, and add smth like opencv_nonfree246d.dll to Additional Dependencies field.
For details, please, see http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html#the-local-method

Boost error, trouble compiling xtime.hpp

I've been working on a C++ project using Boost, and between compiles, I must have upgraded something in boost without meaning to or something, because now Boost dependencies won't compile:
In file included from /usr/include/boost/thread/pthread/mutex.hpp:14:0,
from /usr/include/boost/thread/mutex.hpp:16,
from /usr/include/boost/thread/pthread/thread_data.hpp:12,
from /usr/include/boost/thread/thread.hpp:17,
from /usr/include/boost/thread.hpp:13,
from /blah.h:4,
from bluh.h:3,
from bleh/main.cpp:4:
/usr/include/boost/thread/xtime.hpp:23:5: error: expected identifier before numeric constant
/usr/include/boost/thread/xtime.hpp:23:5: error: expected '}' before numeric constant
/usr/include/boost/thread/xtime.hpp:23:5: error: expected unqualified-id before numeric constant
/usr/include/boost/thread/xtime.hpp:46:14: error: expected type-specifier before 'system_time'
In file included from /usr/include/boost/thread/pthread/mutex.hpp:14:0,
from /usr/include/boost/thread/mutex.hpp:16,
from /usr/include/boost/thread/pthread/thread_data.hpp:12,
from /usr/include/boost/thread/thread.hpp:17,
from /usr/include/boost/thread.hpp:13,
from /blah,
from /bleh,(changed these names, obviously)
from /bluh /main.cpp:4:
/usr/include/boost/thread/xtime.hpp: In function 'int xtime_get(xtime*, int)':
/usr/include/boost/thread/xtime.hpp:73:40: error: 'get_system_time' was not declared in this scope
/usr/include/boost/thread/xtime.hpp:73:40: note: suggested alternative:
/usr/include/boost/thread/thread_time.hpp:19:24: note: 'boost::get_system_time'
/usr/include/boost/thread/xtime.hpp: At global scope:
/usr/include/boost/thread/xtime.hpp:88:1: error: expected declaration before '}' token
make[2]: *** [CMakeFiles/edge_based_tracker.dir/main.o] Error 1
make[1]: *** [CMakeFiles/edge_based_tracker.dir/all] Error 2
make: *** [all] Error 2
Any ideas? I tried changing TIME_UTC to TIME_UTC_ as this was recommended to me on another site, but that didn't seem to help.
EDIT: The Boost Version is Version: 1.48.0.2. I've attached xtime below:
// Copyright (C) 2001-2003
// William E. Kempf
// Copyright (C) 2007-8 Anthony Williams
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_XTIME_WEK070601_HPP
#define BOOST_XTIME_WEK070601_HPP
#include <boost/thread/detail/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/thread/thread_time.hpp>
#include <boost/date_time/posix_time/conversion.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost {
enum xtime_clock_types
{
TIME_UTC=1 //LINE 23
// TIME_TAI,
// TIME_MONOTONIC,
// TIME_PROCESS,
// TIME_THREAD,
// TIME_LOCAL,
// TIME_SYNC,
// TIME_RESOLUTION
};
struct xtime
{
#if defined(BOOST_NO_INT64_T)
typedef int_fast32_t xtime_sec_t; //INT_FAST32_MIN <= sec <= INT_FAST32_MAX
#else
typedef int_fast64_t xtime_sec_t; //INT_FAST64_MIN <= sec <= INT_FAST64_MAX
#endif
typedef int_fast32_t xtime_nsec_t; //0 <= xtime.nsec < NANOSECONDS_PER_SECOND
xtime_sec_t sec;
xtime_nsec_t nsec;
operator system_time() const
{
return boost::posix_time::from_time_t(0)+
boost::posix_time::seconds(static_cast<long>(sec))+
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
boost::posix_time::nanoseconds(nsec);
#else
boost::posix_time::microseconds((nsec+500)/1000);
#endif
}
};
inline xtime get_xtime(boost::system_time const& abs_time)
{
xtime res;
boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
res.sec=static_cast<xtime::xtime_sec_t>(time_since_epoch.total_seconds());
res.nsec=static_cast<xtime::xtime_nsec_t>(time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second()));
return res;
}
inline int xtime_get(struct xtime* xtp, int clock_type)
{
if (clock_type == TIME_UTC)
{
*xtp=get_xtime(get_system_time());
return clock_type;
}
return 0;
}
inline int xtime_cmp(const xtime& xt1, const xtime& xt2)
{
if (xt1.sec == xt2.sec)
return (int)(xt1.nsec - xt2.nsec);
else
return (xt1.sec > xt2.sec) ? 1 : -1;
}
} // namespace boost
#include <boost/config/abi_suffix.hpp>
#endif //BOOST_XTIME_WEK070601_HPP
EDIT: To make it clear, the code is failing on an import of boost/thread.hpp
For those running into the same issue and struggling to find the solution here.
Derived from noodlebox' link (https://svn.boost.org/trac/boost/ticket/6940):
You can edit /usr/include/boost/thread/xtime.hpp (or whereever your xtime.hpp lies)
and change all occurrences of TIME_UTC to TIME_UTC_ - Probably around lines 23 and 71.
i.e. sed -i 's/TIME_UTC/TIME_UTC_/g' /usr/include/boost/thread/xtime.hpp
If you're getting syntax errors when using Boost, you may need to compile your code with -std=c++11.
The TIME_UTC issue you might have read about is a side effect of using c++11. TIME_UTC is now defined as a macro in c++11, so you will need to either replace all instances of TIME_UTC with TIME_UTC_, or just use a newer (1.50.0+) version of Boost where this has been fixed already.
See: https://svn.boost.org/trac/boost/ticket/6940
Since you do not show your code, we can only guess. My guess is that you define TIME_UTC macro somewhere in your code. This macro messes-up xtime.hpp header.

Unable to compile simple CUDA example

test.cu:
#include <iostream>
#include "book.h"
__global__ void add( int a, int b, int *c ) {
*c = a + b;
}
int main( void ) {
int c;
int *dev_c;
HANDLE_ERROR( cudaMalloc( (void**)&dev_c, sizeof(int) ) );
add<<<1,1>>>( 2, 7, dev_c );
HANDLE_ERROR( cudaMemcpy( &c,
dev_c,
sizeof(int),
cudaMemcpyDeviceToHost ) );
printf( "2 + 7 = %d\n", c );
cudaFree( dev_c );
return 0;
}
I am trying to compile above example test.cu. I tried with nvcc test.cu but compiler gives error
4.cu:2:18: fatal error: book.h: No such file or directory
compilation terminated.
How can I tell compiler where book.h is present? I have installed CUDA in /usr/local/cuda.
Do I need to make Makefile?
I am new to CUDA and Makefile so question might seem trivial.
Book.h is not CUDA. It is used by "Cuda by Example" for some easy stuff.
In this example it is needed to provide the HANDLE_ERROR, you should write your own code to handle errors.
Here you can find the book.h code: http://code.google.com/p/cuda-examples/source/browse/trunk/common/book.h?r=3
I believe that using quotes ("") tells the compiler to look in the same directory as the code file, so you may want to try <book.h> instead of "book.h.
Presuming that book.h is a file included with CUDA. I've never used it before.

Resources