Ask Your Question
0

I install OpenCv in a raspberry pi 3 with c++

asked 2020-08-28 09:19:55 -0600

dmata24 gravatar image

Hello everyone. I've been working on a project with OpenCV on Visual Studio but I want to perform some tests on a Raspberry Pi 3, I haven't found accurate information about how can I use OpenCV in a Raspberry Pi with c++ because most of the information is about using OpenCV with python. One of my ideas was to install windows on the Raspberry Pi and then installing Visual studio community (not the visual studio code) as I did on my laptop but I'm not quite sure that it is possible to do it that way. My other idea is to use Raspbian and then install OpenCV but I want to use c++ instead of python. I hope someone could help me to solve this issue.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-08-28 11:15:44 -0600

kbarni gravatar image

Windows doesn't run on the Rasp. But Linux (Raspbian) is simple...just get used to the fact that it's different than Windows. i find Linux much better adapted to development than Windows.

So to install opencv, just type at the command line:

sudo apt install libopencv-dev

You don't even need a complex IDE (anyway, it won't be fast on a Raspberry Pi). Create a file called Makefile near your cpp file:

CC = g++
SOURCES = main.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE = MyProgram
CFLAGS = -c
CFLAGS += $(shell pkg-config opencv4  --cflags) 
LDFLAGS= $(shell pkg-config opencv4 --libs)

ifeq "$(CFG)" "Debug"
    CFLAGS += -Wall -O0 -g
        LDFLAGS += -g
else
    CFLAGS += -w -O3 -Ofast -std=c++11
        LDFLAGS += -s
endif

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
    @Echo "\n***  Linking  ***"
    $(CC) $(OBJECTS) $(LDFLAGS) -o $(EXECUTABLE)

%.o: %.cpp
    @Echo "\n***  Compiling" $< "  ***"
    $(CC) $(CFLAGS) -I$(INCLUDEDIRS) $< -o $@

clean:
    rm -rf *.o $(EXECUTABLE)

You might need to do some modifications according to your configuration.

Now, when you finished the development, just type: make. It will build your code.

If you ant a full-blown IDE, I suggest QT Creator. It's easy to configure for OpenCV.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-08-28 09:19:55 -0600

Seen: 2,087 times

Last updated: Aug 28 '20