Compiler does not recognize OpenCV library - c++

I am using Visual studio 2013 and opencv 3.0.0.
I would like to run this code:
#include <opencv\cv.h>
#include <opencv\highgui.h>
using namespace cv;
int main(){
//Generate matrix to store image
Mat image;
//initialize capture
VideoCapture cap;
cap.open(0);
//Create window to show image
namedWindow("window", 1);
while (1){
//copy webcam stream to image
cap >> image;
//print image to screen
imshow("window", image);
//delay 33ms
waitKey(33);
}
}
However, I got the following errors:
first.cpp(12): error C2065: 'VideoCapture' : undeclared identifier
1>first.cpp(12): error C2146: syntax error : missing ';' before identifier 'cap'
1>first.cpp(12): error C2065: 'cap' : undeclared identifier
1>first.cpp(13): error C2065: 'cap' : undeclared identifier
1>first.cpp(13): error C2228: left of '.open' must have class/struct/union
1> type is 'unknown-type'
1>first.cpp(16): error C3861: 'namedWindow': identifier not found
1>first.cpp(20): error C2065: 'cap' : undeclared identifier
1>first.cpp(23): error C3861: 'imshow': identifier not found
1>first.cpp(26): error C3861: 'waitKey': identifier not found
1>
1>Build FAILED.
I linked the library conveniently. The compiler receives the opencv library. However, it gives such errors.

Related

TrySubmitThreadpoolCallback undeclared identifier

env
Win10, VC6.0
question
When I use windows default thread pool to submit workers,
It compile error. I use VC6.0, and having included Windows.h
but it can't find the function. Please help me.
main.cpp
#include "main.h"
int KeyMap[128];
int main()
{
ScriptHeadTail* pSht = (ScriptHeadTail*)KeyMap[101];
if (pSht != NULL){
TrySubmitThreadpoolCallback(ProcessHook, (LPVOID)(pSht->head), NULL);
}
Sleep(1000);
return 1;
}
VOID CALLBACK ProcessHook(PTP_CALLBACK_INSTANCE instance, PVOID lParam)
{
ExecuteScript* pScript = (ExecuteScript*)lpParam;
while (pScript != NULL){
switch (pScript->type)
{
case KEYBOARD :
{
printf("send key : %d\n", pScript->value);
break;
}
case LBUTTON :
{
printf("left button down : %d\n", pScript->value);
break;
}
case RBUTTON :
{
break;
}
case IDLE :
{
Sleep(pScript->value);
break;
}
}
pScript = pScript->next;
}
return 1;
}
main.h
#include <Windows.h>
#include <stdio.h>
struct ExecuteScript
{
int type;
int value;
ExecuteScript* next;
};
struct ScriptHeadTail
{
ExecuteScript* head;
ExecuteScript* tail;
};
BOOL Init(LPCSTR configFile);
BOOL LoadConfigFile(const char* configFile);
VOID CALLBACK ProcessHook(PTP_CALLBACK_INSTANCE instance, PVOID lParam);
const int ASCII_LEN = 128;
const int KEYBOARD = 1;
const int LBUTTON = 2;
const int RBUTTON = 3;
const int IDLE = 4;
result
--------------------Configuration: ReadFileTest - Win32 Debug---------- ----------
Compiling...
main.cpp
c:\users\jasey\windows-program\readfiletest\main.h(20) : error C2065: 'PTP_CALLBACK_INSTANCE' : undeclared identifier
c:\users\jasey\windows-program\readfiletest\main.h(20) : error C2146: syntax error : missing ')' before identifier 'instance'
c:\users\jasey\windows-program\readfiletest\main.h(20) : warning C4229: anachronism used : modifiers on data are ignored
c:\users\jasey\windows-program\readfiletest\main.h(20) : error C2182: 'ProcessHook' : illegal use of type 'void'
c:\users\jasey\windows-program\readfiletest\main.h(20) : error C2059: syntax error : ')'
c:\users\jasey\windows-program\readfiletest\main.cpp(13) : error C2065: 'TrySubmitThreadpoolCallback' : undeclared identifier
c:\users\jasey\windows-program\readfiletest\main.cpp(60) : error C2146: syntax error : missing ')' before identifier 'instance'
c:\users\jasey\windows-program\readfiletest\main.cpp(60) : warning C4229: anachronism used : modifiers on data are ignored
c:\users\jasey\windows-program\readfiletest\main.cpp(60) : error C2182: 'ProcessHook' : illegal use of type 'void'
c:\users\jasey\windows-program\readfiletest\main.cpp(60) : error C2086: 'ProcessHook' : redefinition
c:\users\jasey\windows-program\readfiletest\main.cpp(60) : error C2059: syntax error : ')'
c:\users\jasey\windows-program\readfiletest\main.cpp(61) : error C2143: syntax error : missing ';' before '{'
c:\users\jasey\windows-program\readfiletest\main.cpp(61) : error C2447: missing function header (old-style formal list?)
执行 cl.exe 时出错.
Creating browse info file...
ReadFileTest.exe - 1 error(s), 0 warning(s)
That API was introduced in Windows Vista. Latest Windows SDK supported in VC 6 is for windows server 2003, it's older than Vista.
Best way to fix is upgrade Visual C++ to some newer version.

Error Using mex matlab 2014a windows x64

I got several errors while trying to use mex function on matlab 2014a with windows 7 x64. The most simple example of any mex generates the error listed as follows. I used windows 7.1 sdk compiler, vc++ 2010 compiler and vc++ compiler and the error doesn't change a thing. Anyone have experienced this issue as well while using this configurations? I would apreciatte some help with this.
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(37) : error C2143: syntax error : missing ';' before '*'
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(37) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(37) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(42) : error C2146: syntax error : missing ';' before identifier 'f'
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(42) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(42) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(75) : error C2065: 'mxFunctionPtr' : undeclared identifier
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(75) : error C2146: syntax error : missing ')' before identifier 'f'
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(75) : error C2513: 'const char **' : no variable declared before '='
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(75) : error C2059: syntax error : ')'
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(120) : error C2061: syntax error : identifier 'mxArray'
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(171) : error C2065: 'mxArray' : undeclared identifier
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(172) : error C2065: 'pa' : undeclared identifier
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(172) : error C2182: 'mexMakeArrayPersistent' : illegal use of type 'void'
C:\Program Files\MATLAB\R2014a\extern\include\mex.h(172) : fatal error C1903: unable to recover from previous error(s);
stopping compilation
EDIT 1 :
as Sugested below, all the errors changed to this:
error C2014: preprocessor command must start as first
error C2061: syntax error : identifier 'mxArray'
error C2065: 'nrhs' : undeclared identifier
error C3861: 'mexErrMsgIdAndTxt': identifier not found
error C3861: 'mexErrMsgIdAndTxt': identifier not found
error C2065: 'prhs' : undeclared identifier
error C2065: 'prhs' : undeclared identifier
error C3861: 'mxGetN': identifier not found
error C3861: 'mxGetN': identifier not found
error C3861: 'mexErrMsgIdAndTxt': identifier not found
error C2065: 'prhs' : undeclared identifier
error C3861: 'mxGetN': identifier not found
error C2065: 'prhs' : undeclared identifier
error C3861: 'mxGetPr': identifier not found
error C2065: 'prhs' : undeclared identifier
error C3861: 'mxGetPr': identifier not found
error C2065: 'prhs' : undeclared identifier
error C3861: 'mxGetM': identifier not found
error C2065: 'prhs' : undeclared identifier
error C3861: 'mxGetM': identifier not found
error C2065: 'plhs' : undeclared identifier
error C2065: 'mxREAL' : undeclared identifier
error C3861: 'mxCreateDoubleMatrix': identifier not
error C2065: 'plhs' : undeclared identifier
error C3861: 'mxGetPr': identifier not found
fatal error C1075: end of file found before the left
brace '{' at 'pukkernelMex.cpp(3)' was matched
EDIT 2 - Contents of pukkernel:
#include <stdio.h>
#include <math.h>
extern "C" { #include "mex.h" }
void pukKernel(double *A, double *B, int rowsA, int rowsB, int columns, double *out)
{
double w = 1.0;
double s = 1.0;
double cte1 = 1/s;
double cte2 = sqrt(pow(2,(1/w))-1);
for (int pattA = 0; pattA < rowsA; pattA++) {
for (int pattB = 0; pattB < rowsB; pattB++) {
double norma = 0;
for (int c = 0; c < columns; c++) {
norma += pow(A[pattA+(c)*rowsA] - B[pattB+(c)*rowsB], 2);
}
norma = sqrt(norma);
double de = 2*norma;
double aux = cte1 * de * cte2;
out[pattA+(pattB)*rowsA] = 1 / pow((1+pow(aux,2)), w);
}
}
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs != 2) {
mexErrMsgIdAndTxt("Test:pukkernel:nrhs.",
"Two inputs required.");
}
if (nlhs != 1) {
mexErrMsgIdAndTxt("Test:pukkernel:nlhs",
"One output required.");
}
if (mxGetN(prhs[0]) != mxGetN(prhs[1])) {
mexErrMsgIdAndTxt("Test:pukkernel:differentDimensions",
"Input matrixes must have same dimensions.");
}
// Input
int columns = mxGetN(prhs[0]);
double *A = (double *) mxGetPr(prhs[0]);
double *B = (double *) mxGetPr(prhs[1]);
int rowsA = mxGetM(prhs[0]);
int rowsB = mxGetM(prhs[1]);
// Output
plhs[0] = mxCreateDoubleMatrix(rowsA, rowsB, mxREAL);
double *outMatrix = mxGetPr(plhs[0]);
pukKernel(A, B, rowsA, rowsB, columns, outMatrix);
}

engine.h is not recognized in Visual Studio c++

I've make all the settings in Visual for this code:
#include "stdafx.h"
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#define BUFSIZE 1000
int main ()
{
Engine *ep;
if (!(ep = engOpen("\0"))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}
system("pause");
return 0;
}
and i still get this error:
Error 2 error C2065: 'Engine' : undeclared identifier
Error 3 error C2065: 'ep' : undeclared identifier
Error 4 error C2065: 'ep' : undeclared identifier
Error 5 error C3861: 'engOpen': identifier not found

OpenCV 2.4.8 Code Error in Microsoft Visual C ++ 2010 Express

I am new to to OpenCV and C++ programming.
I recently installed and configure OpenCV 2.4.8 with Visual Studio 2010 through this link:
http://opencv-srf.blogspot.com/2013/05/installing-configuring-opencv-with-vs.html
Then I test if i did make it right by testing this code:
#include "opencv2/highgui/highgui.hpp"
#include "StdAfx.h"
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, const char** argv )
{
Mat img = imread("C:\Users\jay\Google Drive\profilepic", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
return 0;
}
Unfortunately, it gave errors:
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1> ConsoleApplication1.cpp
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(1): warning C4627: '#include "opencv2/highgui/highgui.hpp"': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(5): error C2871: 'cv' : a namespace with this name does not exist
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(10): error C2065: 'Mat' : undeclared identifier
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(10): error C2146: syntax error : missing ';' before identifier 'img'
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(10): error C2065: 'img' : undeclared identifier
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(10): warning C4129: 'j' : unrecognized character escape sequence
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(10): warning C4129: 'G' : unrecognized character escape sequence
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(10): warning C4129: 'p' : unrecognized character escape sequence
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(10): error C2065: 'CV_LOAD_IMAGE_UNCHANGED' : undeclared identifier
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(10): error C3861: 'imread': identifier not found
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(12): error C2065: 'img' : undeclared identifier
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(12): error C2228: left of '.empty' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(19): error C2065: 'CV_WINDOW_AUTOSIZE' : undeclared identifier
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(19): error C3861: 'namedWindow': identifier not found
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(20): error C2065: 'img' : undeclared identifier
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(20): error C3861: 'imshow': identifier not found
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(22): error C3861: 'waitKey': identifier not found
1>c:\users\jay\documents\visual studio 2010\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(24): error C3861: 'destroyWindow': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Hope you can tell me what is wrong with my code.
I am new to this OpenCV thing and C++.
The line
#include "StdAfx.h"
should be first, before any other includes.
That's why the compiler warns you that it skipped the highgui header.

'random' : identifier not found error

I'm trying to port a code that was written for UNIX to Visual studio and I'm getting the following errors
\random.cpp(29): error C3861: 'initstate': identifier not found
\random.cpp(37): error C3861: 'random': identifier not found
\random.cpp(49): error C3861: 'random': identifier not found
\random.cpp(51): error C3861: 'random': identifier not found
\random.cpp(63): error C3861: 'random': identifier not found
\random.cpp(78): error C3861: 'SQRT': identifier not found
\random.cpp(78): error C3861: 'LOG': identifier not found
\random.cpp(78): error C3861: 'COS': identifier not found
\random.cpp(87): error C3861: 'ABS': identifier not found
The code is long but the I already included math.h but I'm still getting these errors. It could be that those functions are UNIX-only! If so, what are my options to go about it?
Here's a modified sample of my code (the lines that are giving me errors);
if( NULL == initstate(2, rngState, 256) )
do something...
int r = (int)( (rangeEnd - rangeStart) * random() );
double z = SQRT(-2.0 * LOG(x1)) * COS(2.0 * M_PI * x2);
SQRT -> sqrt
LOG -> log
COS -> cos
random -> rand (Don't forget to # include <stdlib.h> for that)
And write the initstate before main or make a forward declaration.
Include stdlib.h and use function rand().
Also the functions has names in lowercase cos, log, sqrt.