Ask Your Question

cagdas001's profile - activity

2019-04-22 11:40:32 -0500 received badge  Notable Question (source)
2019-04-22 11:40:32 -0500 received badge  Popular Question (source)
2018-09-28 18:32:30 -0500 received badge  Famous Question (source)
2018-04-05 04:23:43 -0500 received badge  Notable Question (source)
2018-01-18 08:35:02 -0500 received badge  Popular Question (source)
2017-06-07 06:45:10 -0500 asked a question Which camera should I use for my application?

Hi, I would like to get advice from experienced users. Which camera would you prefer for object/person tracking tasks in OpenCV? Probably I'll get a USB webcam but even though I would like to get advice about other cameras besides USBs.

Or which specs should I check when buying?

2017-05-29 04:19:48 -0500 received badge  Enthusiast
2017-05-28 05:46:34 -0500 received badge  Scholar (source)
2017-05-28 05:43:19 -0500 received badge  Self-Learner (source)
2017-05-28 05:40:39 -0500 commented question Build Application with Static Libraries

Problem solved after a few steps. Thank you all

  1. step, to statically link your application

First, read the steps that I wrote in my question post. They're actually completely correct, just reset the CMake cache and reload the project in case of you're facing any issue. I had already done that before but the problem had not solved. The trick is, try it out again and again.

After rebuilding the application with statically linked libraries, if you're working with a video file like me, you'll probably face a new issue. Your application can't open the video file on another computer.

  1. step, to solve this

In your OpenCV build directory, there is a file named as opencv_ffmpegXXX.dll (310 in my case), put it in the same directory with your EXE.

2017-05-28 05:39:17 -0500 commented question Build Application with Static Libraries

Unfortunately, I can't. "New users must wait 2 days". I'm writing here as the comment. You can write as the answer, if would you like. I'll mark as solution

2017-05-28 05:19:57 -0500 commented question Build Application with Static Libraries

Ok solved, related to the codec. Put the opencv_ffmpeg310.dll with the same directory with your EXE on the new machine. I'm writing the solution as the answer.

2017-05-28 05:11:59 -0500 commented question Build Application with Static Libraries

@berak I reset the CMake cache and reloaded the project after adding the new message command, after a long waiting, IDE has indexed the files and libraries again. EXE size increased to 9.5MB now. Tried it on my virtual machine which does not have OpenCV installed, EXE is working but I'm having another problem. Even though I put the video.mp4 file to correct directory (C:\OpenCV\video.mp4), EXE can't find the file

2017-05-28 04:32:49 -0500 commented question Build Application with Static Libraries

@berak I have changed the environment variable, %OpenCV_DIR% is pointing to correct directory. How can I check OpenCV_LIBS ?

2017-05-28 04:29:25 -0500 commented question Build Application with Static Libraries

There is a Linker option for Static linking in Visual Studio, so you don't need to make any change on CMake. My IDE is using MinGW and CMake, I need to solve this with MinGW or CMake parameters

2017-05-28 04:01:09 -0500 commented question Build Application with Static Libraries

I don't need all libraries, my application is just a simple application. AFAIK, Visual Studio does not use CMake, so it's a little bit different. I edited the post with app code and CMake, you can look again

2017-05-27 14:37:24 -0500 received badge  Organizer (source)
2017-05-27 13:50:41 -0500 asked a question Build Application with Static Libraries

Hi all,

I'm trying to statically link my C++ (CMake) application to run on another computer which does not have OpenCV installed.

So far,

  1. I built OpenCV from source by setting BUILD_SHARED_LIBS to OFF, so I can see library files under lib directory. (with .a extension)

  2. I edited the environment variable for the new build of OpenCV, my IDE does see include directories and files, so this step also seems ok.

  3. Added "-static" parameter to target_link_libraries command in CMake:

target_link_libraries(HoGPeopleDetector ${OpenCV_LIBS} "-static")

Then rebuilt the application, EXE size increased to 1.6 MB from 200 KB. So I guess linking process was successful.

The application works well when I run it within my IDE. However, when I try to run it from the EXE file, it still expects DLL files. (libopencv_core310.dll and maybe more)

IDE: CLion 2017.1.2 OpenCV: 3.1

Program Code:

#include <iostream>
#include <opencv2/objdetect.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>

using namespace cv;
using namespace std;

static void detectAndDraw(const HOGDescriptor &hog, Mat &img)
vector<Rect> found, found_filtered;

hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);

for(size_t i = 0; i < found.size(); i++ )
    Rect r = found[i];

    size_t j;

    for ( j = 0; j < found.size(); j++ )
        if ( j != i && (r & found[j]) == r )

    if ( j == found.size() )

for (size_t i = 0; i < found_filtered.size(); i++)
    Rect r = found_filtered[i];

    r.x += cvRound(r.width*0.1);
    r.width = cvRound(r.width*0.8);
    r.y += cvRound(r.height*0.07);
    r.height = cvRound(r.height*0.8);
    rectangle(img,,, cv::Scalar(0,255,0), 3);

int main(int argc, char** argv)

cout << "Cikis icin Q ya da ESC ye basin\n";

HOGDescriptor hog;
namedWindow("people detector", 1);

string pattern_glob = "";
string video_filename = "C:\\OpenCV\\video.mp4";

VideoCapture vc;
Mat frame;;
if (!vc.isOpened())
    throw runtime_error(string("Dosya acilamadi: " + video_filename));

for (;;)
    vc >> frame;

    if (frame.empty())

    detectAndDraw(hog, frame);

    imshow("people detector", frame);
    int c = waitKey( vc.isOpened() ? 10 : 0 ) & 255;
    if ( c == 'q' || c == 'Q' || c == 27)

return 0;


cmake_minimum_required(VERSION 3.7)


find_package(OpenCV REQUIRED)

set(SOURCE_FILES main.cpp)
add_executable(HoGPeopleDetector ${SOURCE_FILES})

target_link_libraries(HoGPeopleDetector ${OpenCV_LIBS} "-static")
2016-11-19 13:39:35 -0500 received badge  Student (source)
2016-11-19 13:36:37 -0500 commented question undefined reference to `cv::imread

I finally solved my problem. I'm using MinGW 5.3 on my IDE. But CMake is using MinGW 4.9 as default, if you select "Use default native compilers". So you should select "specify native compilers" and give the path of MinGW that using with your IDE. And then you should run "mingw32-make.exe" from the same MinGW again. - I could not write as answer, therefore I'm writing as comment

2016-11-19 08:07:13 -0500 commented question undefined reference to `cv::imread

Ok I'm already doing same things with you wrote. I don't understand what I'm doing wrong. I will try with also mingw64 I would write the result

2016-11-19 05:42:14 -0500 commented question undefined reference to `cv::imread

Which folder should I give? There are 2 folders. (sources and build)

2016-11-19 05:08:13 -0500 commented question undefined reference to `cv::imread

Yes I tried it, already my IDE doing that with "Reset CMake Cache and Reload" option. I'm giving "sources" folder of OpenCV to CMake-GUI

2016-11-18 14:29:19 -0500 commented question undefined reference to `cv::imread

Actually I gave the "sources" folder (extracted by OpenCV installer) to CMake-GUI. As far as I know sources folder is the same with github. And as build folder, I gave a empty folder ("mingw-build" in my case) After the "mingw32-make" command, generated DLLs and some exe files in "bin" folder. We already need these DLLs as far as I know, am I wrong? I added the "bin" folder to system path. But I can't compile the project still.

2016-11-18 14:14:07 -0500 commented question undefined reference to `cv::imread

OK I replaced screenshots. I will try your response now then I would write the result

2016-11-18 14:12:09 -0500 received badge  Editor (source)
2016-11-18 13:54:26 -0500 asked a question undefined reference to `cv::imread

Hi, I'm using CLion as IDE and trying to link OpenCV. But I'm having problem even with a very simple app.

I prepared OpenCV binaries with these steps.

  1. Extract OpenCV files (from official website)

  2. Generate a build folder with CMake

  3. In the directory generated by CMake, execute "mingw32-make" command

  4. Add "OPENCV_DIR" to system variables. ("C:\OpenCV\mingw-build" in my case)

  5. Add "%OPENCV_DIR%\bin" to system path

My CPP Code:

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;

int main() {
string file = "image.jpg";
Mat img = imread(file.c_str(), 1);
namedWindow("image", WINDOW_AUTOSIZE);
imshow("image", img);
return 0;

My CMakeLists.txt

cmake_minimum_required(VERSION 3.6)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

find_package(OpenCV REQUIRED)

set(SOURCE_FILES main.cpp)
add_executable(OpenCVFirstDemo ${SOURCE_FILES})

target_link_libraries(OpenCVFirstDemo ${OpenCV_LIBS})

And when I try to build, I'm getting the following messages.

"C:\Program Files (x86)\JetBrains\CLion 2016.2.3\bin\cmake\bin\cmake.exe" --build C:\Users\CagdasX\.CLion2016.2\system\cmake\generated\OpenCVFirstDemo-f9ecc709\f9ecc709\Debug --target OpenCVFirstDemo -- -j 8
Scanning dependencies of target OpenCVFirstDemo
[ 50%] Building CXX object CMakeFiles/OpenCVFirstDemo.dir/main.cpp.obj
[100%] Linking CXX executable OpenCVFirstDemo.exe
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/CagdasX/ClionProjects/OpenCVFirstDemo/main.cpp:9: undefined reference to `cv::imread(cv::String const&, int)'
C:/Users/CagdasX/ClionProjects/OpenCVFirstDemo/main.cpp:10: undefined reference to `cv::namedWindow(cv::String const&, int)'
C:/Users/CagdasX/ClionProjects/OpenCVFirstDemo/main.cpp:11: undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
C:/Users/CagdasX/ClionProjects/OpenCVFirstDemo/main.cpp:12: undefined reference to `cv::waitKey(int)'
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In function `ZN2cv6StringC1EPKc':
C:/OpenCV/sources/modules/core/include/opencv2/core/cvstd.hpp:625: undefined reference to `cv::String::allocate(unsigned int)'
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In function `ZN2cv6StringD1Ev':
C:/OpenCV/sources/modules/core/include/opencv2/core/cvstd.hpp:667: undefined reference to `cv::String::deallocate()'
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In function `ZN2cv3MatD1Ev':
C:/OpenCV/sources/modules/core/include/opencv2/core/mat.inl.hpp:571: undefined reference to `cv::fastFree(void*)'
CMakeFiles\OpenCVFirstDemo.dir/objects.a(main.cpp.obj): In function `ZN2cv3Mat7releaseEv':
C:/OpenCV/sources/modules/core/include/opencv2/core/mat.inl.hpp:682: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\OpenCVFirstDemo.dir\build.make:112: recipe for target 'OpenCVFirstDemo.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/OpenCVFirstDemo.dir/all' failed
mingw32-make.exe[3]: *** [OpenCVFirstDemo.exe] Error 1
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/OpenCVFirstDemo.dir/rule' failed
mingw32-make.exe[2]: *** [CMakeFiles/OpenCVFirstDemo.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/OpenCVFirstDemo.dir/rule] Error 2
Makefile:117: recipe for target 'OpenCVFirstDemo' failed
mingw32-make.exe: *** [OpenCVFirstDemo] Error 2