Can't use imwrite...

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Can't use imwrite...

opencv-users mailing list
This is my CMakeLists.txt:project(proj)
set(OpenCV_DIR "/usr/lib/opencv")
find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui)

include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(test test.cpp>
target_link_libraries(test ${OpenCV_LIBS})and this is part of my code:#include <opencv/cv.h>
#include <opencv/cv.hpp>
#include <opencv/highgui.h>
#include <opencv/highgui.hpp>

using namespace cv;
using namespace std;

int main(int argv, char **argc)
{      
    //other code
    Mat img(height, width, CV_8UC3);
    //other code

    imwrite("/path", img);
    namedWindow( "Display window", 1 );
    imshow("Display window", img);

    waitKey(0);                                          
    return 0;

}and the error message I get is: undefined reference to cv::imwrite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Mat const&, std::vector<int, std::allocator<int> > const&)imshow works correctly, so I have no clue why imwrite is giving me an error.g++ -o test_1 test_1.cpppkg-config opencv --cflags --libs`` gives the same error.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can't use imwrite...

opencv-users mailing list
What OS and Opencv version???


On 05/25/2017 09:52 AM, A Yahoo! User [hidden email] [OpenCV] wrote:

> This is my CMakeLists.txt:
> |project(proj)set(OpenCV_DIR"/usr/lib/opencv")find_package(OpenCVREQUIRED
> COMPONENTS core imgproc
> highgui)include_directories(${OpenCV_INCLUDE_DIRS})add_executable(test
> test.cpp>target_link_libraries(test ${OpenCV_LIBS})|
> and this is part of my code:
> |#include<opencv/cv.h>#include<opencv/cv.hpp>#include<opencv/highgui.h>#include<opencv/highgui.hpp>usingnamespacecv;usingnamespacestd;intmain(intargv,char**argc){//other
> codeMatimg(height,width,CV_8UC3);//other
> codeimwrite("/path",img);namedWindow("Display
> window",1);imshow("Display window",img);waitKey(0);return0;}|
> and the error message I get is: |undefined reference to
> cv::imwrite(std::basic_string<char, std::char_traits<char>,
> std::allocator<char> > const&, cv::Mat const&, std::vector<int,
> std::allocator<int> > const&)|
> imshow works correctly, so I have no clue why imwrite is giving me an
> error.
> |g++ -o test_1 test_1.cpp|pkg-config opencv --cflags --libs`` gives
> the same error.
>

--
*Martin Noblia*
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can't use imwrite...

opencv-users mailing list
RHEL 6 and OpenCV 2.0.

> On May 25, 2017, at 9:45 AM, Martin Noblia [hidden email] [OpenCV] <[hidden email]> wrote:
>
> What OS and Opencv version???
>
>> On 05/25/2017 09:52 AM, A Yahoo! User [hidden email] [OpenCV] wrote:
>>  
>> This is my CMakeLists.txt:
>> project(proj)
>> set(OpenCV_DIR "/usr/lib/opencv")
>> find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui)
>>
>> include_directories(${OpenCV_INCLUDE_DIRS})
>> add_executable(test test.cpp>
>> target_link_libraries(test ${OpenCV_LIBS})
>> and this is part of my code:
>> #include <opencv/cv.h>
>> #include <opencv/cv.hpp>
>> #include <opencv/highgui.h>
>> #include <opencv/highgui.hpp>
>>
>> using namespace cv;
>> using namespace std;
>>
>> int main(int argv, char **argc)
>> {      
>>     //other code
>>     Mat img(height, width, CV_8UC3);
>>     //other code
>>
>>     imwrite("/path", img);
>>     namedWindow( "Display window", 1 );
>>     imshow("Display window", img);
>>
>>     waitKey(0);                                          
>>     return 0;
>>
>> }
>> and the error message I get is: undefined reference to cv::imwrite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Mat const&, std::vector<int, std::allocator<int> > const&)
>> imshow works correctly, so I have no clue why imwrite is giving me an error.
>> g++ -o test_1 test_1.cpppkg-config opencv --cflags --libs`` gives the same error.
>
> --
> Martin Noblia
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can't use imwrite...

opencv-users mailing list
Have you tried?:

#include <opencv2/imgproc/imgproc.hpp>


On 05/25/2017 12:31 PM, [hidden email] [OpenCV] wrote:

> RHEL 6 and OpenCV 2.0.
>
> On May 25, 2017, at 9:45 AM, Martin Noblia
> [hidden email] <mailto:[hidden email]>
> [OpenCV] <[hidden email] <mailto:[hidden email]>> wrote:
>
>> What OS and Opencv version???
>>
>>
>> On 05/25/2017 09:52 AM, A Yahoo! User [hidden email] [OpenCV] wrote:
>>> This is my CMakeLists.txt:
>>> |project(proj)set(OpenCV_DIR"/usr/lib/opencv")find_package(OpenCVREQUIRED
>>> COMPONENTS core imgproc
>>> highgui)include_directories(${OpenCV_INCLUDE_DIRS})add_executable(test
>>> test.cpp>target_link_libraries(test ${OpenCV_LIBS})|
>>> and this is part of my code:
>>> |#include<opencv/cv.h>#include<opencv/cv.hpp>#include<opencv/highgui.h>#include<opencv/highgui.hpp>usingnamespacecv;usingnamespacestd;intmain(intargv,char**argc){//other
>>> codeMatimg(height,width,CV_8UC3);//other
>>> codeimwrite("/path",img);namedWindow("Display
>>> window",1);imshow("Display window",img);waitKey(0);return0;}|
>>> and the error message I get is: |undefined reference to
>>> cv::imwrite(std::basic_string<char, std::char_traits<char>,
>>> std::allocator<char> > const&, cv::Mat const&, std::vector<int,
>>> std::allocator<int> > const&)|
>>> imshow works correctly, so I have no clue why imwrite is giving me
>>> an error.
>>> |g++ -o test_1 test_1.cpp|pkg-config opencv --cflags --libs`` gives
>>> the same error.
>>
>> --
>> *Martin Noblia*
>

--
*Martin Noblia*
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can't use imwrite...

opencv-users mailing list
I'm on such an old version of OpenCV that my include/ only has /opencv, not even /opencv2, unfortunately.  
I'm having a hard time figuring out how to update on rhel.

> On May 25, 2017, at 6:40 PM, Martin Noblia [hidden email] [OpenCV] <[hidden email]> wrote:
>
> Have you tried?:
>
> #include <opencv2/imgproc/imgproc.hpp>
>
>> On 05/25/2017 12:31 PM, [hidden email] [OpenCV] wrote:
>>  
>> RHEL 6 and OpenCV 2.0.
>>
>> On May 25, 2017, at 9:45 AM, Martin Noblia [hidden email] [OpenCV] <[hidden email]> wrote:
>>
>>>  
>>> What OS and Opencv version???
>>>
>>>> On 05/25/2017 09:52 AM, A Yahoo! User [hidden email] [OpenCV] wrote:
>>>>  
>>>> This is my CMakeLists.txt:
>>>> project(proj)
>>>> set(OpenCV_DIR "/usr/lib/opencv")
>>>> find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui)
>>>>
>>>> include_directories(${OpenCV_INCLUDE_DIRS})
>>>> add_executable(test test.cpp>
>>>> target_link_libraries(test ${OpenCV_LIBS})
>>>> and this is part of my code:
>>>> #include <opencv/cv.h>
>>>> #include <opencv/cv.hpp>
>>>> #include <opencv/highgui.h>
>>>> #include <opencv/highgui.hpp>
>>>>
>>>> using namespace cv;
>>>> using namespace std;
>>>>
>>>> int main(int argv, char **argc)
>>>> {      
>>>>     //other code
>>>>     Mat img(height, width, CV_8UC3);
>>>>     //other code
>>>>
>>>>     imwrite("/path", img);
>>>>     namedWindow( "Display window", 1 );
>>>>     imshow("Display window", img);
>>>>
>>>>     waitKey(0);                                          
>>>>     return 0;
>>>>
>>>> }
>>>> and the error message I get is: undefined reference to cv::imwrite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Mat const&, std::vector<int, std::allocator<int> > const&)
>>>> imshow works correctly, so I have no clue why imwrite is giving me an error.
>>>> g++ -o test_1 test_1.cpppkg-config opencv --cflags --libs`` gives the same error.
>>>
>>> --
>>> Martin Noblia
>
> --
> Martin Noblia
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can't use imwrite...

opencv-users mailing list
In order to save image, you have to give image format as well.  

 i see in your code. you did not mention image format.
 

 below in blod form shows format.
 

 imwrite("/path.jpg", img);
Now run your code. it will work.
Hopet his helps. cheers.







 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can't use imwrite...

opencv-users mailing list
Path does include .jpg (I've also tried with .png and .bmp).
Apologies for not making this clear in the initial issue.
This is also a compile time issue and not runtime.

> On May 26, 2017, at 1:22 AM, [hidden email] [OpenCV] <[hidden email]> wrote:
>
> In order to save image, you have to give image format as well.
>
>
> i see in your code. you did not mention image format.
>
> below in blod form shows format.
>
>>>>> imwrite("/path.jpg", img);
>>>>> Now run your code. it will work.
>>>>> Hopet his helps. cheers.
>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can't use imwrite...

opencv-users mailing list
You have to write the Mat as Image data structure here.
Mat img;
imwrite("image.png",img)
Loading...