Open CV won't compile - opencv

I'm trying to compile some opencv code, but it is failing. I'm pretty sure I have the libraries included but it still has undefined references to the functions.
I'm running this command:
gcc -lhighgui -lcvaux -lcxcore -I /usr/local/include/opencv/ -L /usr/local/lib/ -o hello_world hello_world.c
and get this result
foo.cpp:(.text._ZN3Foo3barEv[Foo::bar()]+0x1f): undefined reference to `cvLoadImage'
foo.cpp:(.text._ZN3Foo3barEv[Foo::bar()]+0x2d): undefined reference to `cvWaitKey'
with this code:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
class Foo{
public:
void bar(){
IplImage* img = 0;
img=cvLoadImage("C:/.../Pictures/image.jpg");
cvWaitKey(0);
system("PAUSE");
}
};
extern "C" {
Foo* Foo_new(){ return new Foo(); }
void Foo_bar(Foo* foo){ foo->bar(); }
}

Related

How to use LLVM's SanitizerCoverage code coverage instrumentation with a shared library?

I have a shared library linked to an executable for which I would like to have code coverage instrumentation using custom _sanitizer_cov_trace_pc* functions.
library.cc
#include <stdio.h>
void so_function() {
printf("SO function.");
}
callbacks.cc
#include <stdint.h>
#include <stdio.h>
#include <sanitizer/coverage_interface.h>
extern "C" void __sanitizer_cov_trace_pc_guard_init(uint32_t *start,
uint32_t *stop) {
static uint64_t N;
if (start == stop || *start) return;
printf("INIT: %p %p\n", start, stop);
for (uint32_t *x = start; x < stop; x++)
*x = ++N;
}
extern "C" void __sanitizer_cov_trace_pc_guard(uint32_t *guard) {
if (!*guard) return;
void *PC = __builtin_return_address(0);
char PcDescr[1024];
__sanitizer_symbolize_pc(PC, "%p %F %L", PcDescr, sizeof(PcDescr));
printf("guard: %p %x PC %s\n", guard, *guard, PcDescr);
}
main.cc
#include <stdio.h>
void so_function();
int main(int argc, char **argv) {
so_function();
}
I compiled the library using clang's -fsanitize-coverage=trace-pc-guard into position-independent code (-fPIC) and then I created the shared library using both the resulted object file and callbacks.cc using -fsanitize=address.
I compiled main.cc and linked it with the shared library but it seems like these 2 custom __sanitizer_cov_trace_pc_guard* functions don't get called.
I would like have code coverage instrumentation using these 2 functions only for the shared library, and not for the main executable.

Opencv : No error in code , but webcam not showing in result

I am training out the tutorial in opencv.
it had no error when compile.
I know the code for the tutorial is for opencv2.4 and I had change the coding for cvquery and videoframe.
My output is like this
.
My webcam is working fine but it not showing anything in my result.
If you wish to perform face detection using HaarCascades, you can use this code:
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
CascadeClassifier facecascade;
int main()
{
Mat frame;
facecascade.load("haarcascade_frontalface_alt.xml");
if(facecascade.empty())
{
cout<<"Error";
}
VideoCapture cap(0);
int i=0,j=0,k=0;
while(1)
{
cap>>frame;
Mat frame_gray;
cvtColor(frame,frame_gray,CV_BGR2GRAY);
vector<Rect>faces;
facecascade.detectMultiScale(frame_gray,faces,1.1,2,0|CV_HAAR_SCALE_IMAGE,Size(70,70));
if(faces.size()>0)
{
for(i=0;i<faces.size();i++)
{
rectangle(frame_gray,faces[i],Scalar(200,200,250),2,8,0);
}
char no[5];
sprintf(no,"No. of faces detected = %d",int(faces.size()));
putText(frame_gray,no,Point(10,30),FONT_HERSHEY_TRIPLEX,1,Scalar(255,255,255),1);
imshow("out",frame_gray);
char c= waitKey(5);
if(c=='b')
break;
}
return 0;
}

How to pass a DynamicArray in c++ builder

I'm using C++Builder XE4 with the VCL Win32 platform. I am tring to setup a method that will take a DynamicArray of TPoint as an argument. Below is from my .hpp file for a standard VCL Win32 Form. My declaration for CalcPolygonDetail() is generating the error message: "Error in module NewForm: Incorrect method declaration in class TForm3_cpp" The problem is the argument DynamicArray MyPoints, Can someone show how to setup this declaration correctly. Thanks.
#ifndef NewFormH
#define NewFormH
//----
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include "AdvSpin.hpp"
#include <Vcl.ComCtrls.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Mask.hpp>
DynamicArray<TPoint> MyPoints;
//------------
class TForm3_cpp : public TForm
{
__published: // IDE-managed Components
TImage *Image1;
TLabel *Label2;
----break----
int __fastcall CalcPolygonDetail(DynamicArray<TPoint> MyPoints, bool UseScreenCoordinates );
.
This simple file compiles fine as a Console VCL App on XE5.
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#pragma argsused
#include <tchar.h>
#include <stdio.h>
DynamicArray<System::Types::TPoint> MyPoints;
void __fastcall TestFunction(DynamicArray<System::Types::TPoint> MyPoints2, bool SomeOtherParam)
{
// Do something with this.
MyPoints = MyPoints2;
}
int _tmain(int argc, _TCHAR* argv[])
{
DynamicArray<System::Types::TPoint> MyPoints3;
TestFunction(MyPoints3, true);
return 0;
}
Does this compiles fine for you? Maybe the problem lies somewhere else, because the DynamicArray definition seems correct. I would create a type instead:
typedef DynamicArray<System::Types::TPoint> TMyPoints;
Specially if you are going to use that kind of arrays in your code more than once. But as the example shows, even without this it should work.

Lua does not load libs

I decided to add scripting with Lua. I've downloaded and compiled interpreter. It works fine, but when I want to use any functions from os.* or string.* libs, it says, that "attemt to index global 'os' (a nil value)"
Here is my code and should work, but it does not:
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
extern "C" {
#include "..\liblua\lua.h"
#include "..\liblua\lualib.h"
#include "..\liblua\lauxlib.h"
}
int main(int argc, TCHAR* argv[])
{
lua_State *LuaVM = luaL_newstate();
lua_pushcfunction(LuaVM,luaopen_base);
lua_call(LuaVM,0,0);
lua_pushcfunction(LuaVM,luaopen_math);
lua_call(LuaVM,0,0);
lua_pushcfunction(LuaVM,luaopen_string);
lua_call(LuaVM,0,0);
lua_pushcfunction(LuaVM,luaopen_table);
lua_call(LuaVM,0,0);
int error;
lua_pushstring(LuaVM,"Ver 0.525.5");
lua_setglobal(LuaVM,"Version");
while (true)
{
string strCode;
getline(cin,strCode);
error = luaL_loadbuffer(LuaVM,strCode.c_str(),strCode.length(),"") ||
lua_pcall(LuaVM,0,0,0);
if (error)
{
cout<< lua_tostring(LuaVM,-1)<<endl;
lua_pop(LuaVM,1);
}
}
lua_close(LuaVM);
return 0;
}
What's wrong with it?
In Lua 5.2 the standard luaopen_* functions do not set the corresponding global variables.
Why not copy and adapt the code in linit.c or just call luaL_openlibs?
Otherwise, do what they do: call luaL_requiref for each luaopen_* function.
See http://www.lua.org/source/5.2/linit.c.html#luaL_openlibs.

Stack around the variable 'keypoints' was corrupted

I am using the following part code to get surf features plotted:
I am using the following part code to get surf features plotted:
#include<iostream>
using namespace std;
#include<vector>
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/features2d/features2d.hpp"
using namespace cv;
int main(int argc,char** argv)
{
VideoCapture vid(0);
if (!vid.isOpened())
{
cout<<"Camera not present..Halting the system";
return -1;
}
namedWindow("Camera_Inp",1);
namedWindow("Surfout",1);
Mat camcap,surfimg;
Mat grayimg;
SurfFeatureDetector featureimg(1000);
vector<KeyPoint>keypoints;
while(vid.isOpened()==true)
{
vid>>camcap;
imshow("Camera_Inp",camcap);
cvtColor(camcap,grayimg,CV_RGB2GRAY);
featureimg.detect(grayimg,keypoints);
drawKeypoints(grayimg,keypoints,surfimg,Scalar(255,255,255),0);
imshow("Surfout",surfimg);
if (waitKey(30)>=0)return -1;
}
return -1;
}
Visual Studio gives me the following error:
Stack around the variable 'keypoints' was corrupted.
The visual Studio debugger gives the error that:
Stack around the variable 'keypoints' was corrupted
Any help!!

Resources