Opencv working with python but cant get to work with cpp

Hello all. I got opencv to work with python but it seems that when I try to run this c++ example it is having a hard time finding the associated files. Idk how to link libraries or add a path so hopefully someone knows what I am missing. Thanks

im not sure how to post code either so apologies if it is wrong.

also I changed the paths to match where my files are, you can see that in the terminal

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;


int main( int argc, char** argv )
{
    cvNamedWindow("Capture Example", CV_WINDOW_AUTOSIZE);
    CvCapture* capture = cvCreateCameraCapture(0);
    IplImage* frame;

    while(1)
    {
        frame=cvQueryFrame(capture);
     
        if(!frame) break;

        cvShowImage("Capture Example", frame);

        char c = cvWaitKey(33);
        if( c == 27 ) break;
    }

    cvReleaseCapture(&capture);
    cvDestroyWindow("Capture Example");
    
}; 

MAKEFILE:

INCLUDE_DIRS = 
LIB_DIRS = 
CC=g++

CDEFS=
CFLAGS= -O0 -g $(INCLUDE_DIRS) $(CDEFS)
LIBS= -lrt
CPPLIBS= -L/usr/lib -lopencv_core -lopencv_flann -lopencv_video

HFILES= 
CFILES= 
CPPFILES= capture.cpp

SRCS= ${HFILES} ${CFILES}
CPPOBJS= ${CPPFILES:.cpp=.o}

all:	capture 

clean:
	-rm -f *.o *.d
	-rm -f capture

distclean:
	-rm -f *.o *.d

capture: capture.o
	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $@.o `pkg-config --libs opencv` $(CPPLIBS)

depend:

.c.o:
	$(CC) $(CFLAGS) -c $<

.cpp.o:
	$(CC) $(CFLAGS) -c $<

Also I am using opencv4 which could also be a problem but I dont know exactly what it would be

your code is from the very outdated (and removed in 4.x) c-api, you cannot use it anymore.
current c++ eqiuvalent would be:

#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
cv::namedWindow(“Capture Example”,cv::WINDOW_AUTO);
cv::VideoCapture  capture(0);

while(1)
{
    cv::Mat frame;
    bool ret = capture.read(frame);
 
    if(!ret) break;

    cv::imshow("Capture Example", frame);
    char c = cv::waitKey(33);
    if( c == 27 ) break;
}

}

again, please have a look at docs / turorials

thank you for the reply. I am very new and just trial and error and looking up the errors at this point.

It worked. Thank so much

3 posts were merged into an existing topic: Trying to make a unity plugin for android with Visual Studio/C++: iostream not found