Hello,
I wrote an application to manipute images. It's an easy little app to change size, crop, sharpen, smoothen, optimize contrast and such things. For this I use opencv too. Under Linux all things are fully functional.
But in Windows I cannot open images. To setup wxWidgets I used mostly this guide: https://github.com/PBfordev/wxpbguide , mostly because the script to modify codeblocks as described failed.
I have compiled both versions as static librarys, WxWidgets and Opencv, with success because the compiler creates only an exe file.
bitmap.LoadFile("e:\\test_image.jpg") as for wxWidgets or cvImage = imread("e:\\test_image.jpg", IMREAD_UNCHANGED); cannot open an image in windows but in Linux this is no problem.
Error message:
Can't load image from ressources from "e:\testimage.jpg" Check .rc file.
I don't understand this because i use the filedialog to open images and even hard coded, as in my example above, is not functional.
Thanks in advance.
Can not open images in windows
Re: Can not open images in windows
Which script?ingsew wrote: ↑Fri Sep 15, 2023 8:18 am To setup wxWidgets I used mostly this guide: https://github.com/PBfordev/wxpbguide , mostly because the script to modify codeblocks as described failed.
Compiler creating an exe file has nothing to do with how libraries are linked. The important thing is, does the executable run when the DLLs are not available? IMO, building OpenCV as static is rather unusual, perhaps impossible?
That is because as documented, the default value of the second parameter of wxBitmap::LoadFile() is platform specific and on Windows it is a resource, not a disk file.
So you either need to specify the bitmap type in LoadFile(), e.g., LoadFile("e:\testimage.jpg", wxBITMAP_TYPE_JPEG); or if you do not want to bother with specifying the image format, just use wxImage::LoadFile() which accepts any known bitmap format, and then create a wxBitmap from that wxImage.
BTW, do not forget to call wxInitAllImageHandlers() once in your application.
Re: Can not open images in windows
Thanks for the fast reply
I think you are the one who made this guide. Thank you it is a great guide and easy to understand.
Or another question: Would it be better and easier to compile on windows with VisualStudio. As said, in Linux there were no problems. The program can handle all supported image file in every possible format even with alpha channel (therefore I had to extend OpenCv with some converting functions and also a "readable" imshow function for alpha channels). The opencv imread() function shows a problem in system.cpp (part of opencv) therefore my assumption.
Thanks for your help.
I think you are the one who made this guide. Thank you it is a great guide and easy to understand.
The script to setup codeblock to use wxwidgets version 3.2, in the last? section of the guide. But this was no problem because I could link the newest version.Which script?
You are alright, this was a mistake ofme, writing too fast without thinking. I meant I do not need any other library, neither wxWidget or OpenCv nor the stdc++ ones. All went well. I can call the app by doubleclick the exe file and it starts, but if i want to open an image (open with filedialog or dragging) the error occurs. Even if I only use the cv::imread() function without using wxWidgets LoadFile().I have compiled both versions as static librarys, WxWidgets and Opencv, with success because the compiler creates only an exe file.
Ok, I called wxInitAllImageHandlers() in my constructor, it is because I want to use all possible image types, that wxWidgets and OpenCV supports.That is because as documented, the default value of the second parameter of wxBitmap::LoadFile() is platform specific and on Windows it is a resource, not a disk file.
So you either need to specify the bitmap type in LoadFile(), e.g., LoadFile("e:\testimage.jpg", wxBITMAP_TYPE_JPEG); or if you do not want to bother with specifying the image format, just use wxImage::LoadFile() which accepts any known bitmap format, and then create a wxBitmap from that wxImage.
BTW, do not forget to call wxInitAllImageHandlers() once in your application.
I think this is not the problem in this case, but I don't know exactly, it is because the opencv::imread() function have the same problem. Maybe this is an issue because of compiling both libraries to static with g++ in windows? Is there anything to change because of the compilation Progress.wxBitmap::LoadFile() is platform specific and on Windows it is a resource, not a disk file.
Or another question: Would it be better and easier to compile on windows with VisualStudio. As said, in Linux there were no problems. The program can handle all supported image file in every possible format even with alpha channel (therefore I had to extend OpenCv with some converting functions and also a "readable" imshow function for alpha channels). The opencv imread() function shows a problem in system.cpp (part of opencv) therefore my assumption.
Thanks for your help.
Re: Can not open images in windows
I think this exactly the problem, based both on your code using the default for the second parameter and the error message mentioning resource.
I have no idea why imread() does not work for you, are you sure the path is correct (OpenCV does not support Unicode paths)? You need to check the error message, it should give you a hint.
For example, this would be a bug
Code: Select all
bmp.LoadBitmap("e:\testimage.jpg")
BTW, I wrote an OpenCV bitmap to wxBitmap conversion function (does not support transparency): https://github.com/PBfordev/wxopencvtest
As for using MSVS vs C::B. I believe that MSVS (not VS Code) is the best IDE on Windows. However, since the Express Edition has been abandoned, its licence may prevent some from using the Community Edition. Either way, I doubt the IDE/compiler is an issue here.
Finally, to make sure the libraries are really linked in static, I would recommend either verifying with the Depends tool or running while being sure the required DLLs (compiler, wxWidgets, OpenCV including its own dependencies) are not anywhere in the PATH where the Windows can find them.
As I wrote, linking complete OpenCV statically would probably result into an executable being several hundred megabytes large, is yours that big?
Re: Can not open images in windows
Hi, I will check this today,
Next I will change the loading process for wxWidgets, as you described, after that I give some feedback and for opencv it is more tricky because they prevent compiling to some parts because of license issues. It is not easy to find out what went wrong in this case.
Thanks for your answers und Grüsse aus dem Schwarzwald
.I think this is not the problem in this case, but I don't know exactly
I tested this also with double backslash.I have no idea why imread() does not work for you, are you sure the path is correct (OpenCV does not support Unicode paths)? You need to check the error message, it should give you a hint.
For example, this would be a bug
Code: Alles auswählen
bmp.LoadBitmap("e:\testimage.jpg")
the backslash must be doubled, otherwise "\t" gets converted to a tab character.
bmp.LoadBitmap("e:\testimage.jpg")
As you surely know, to use static libs we have to compile the dependencies to static libs, therefore there are no *.dll files but .a files. and I can run the compiled exe file at an other windows pc without any other files (libs). I used your perfect guide to compile wxWidgets and I tested this also as you described. The same way I compiled opencv (the newest version) which was indeed time consuming to find out and set the right parameters.Finally, to make sure the libraries are really linked in static, I would recommend either verifying with the Depends tool or running while being sure the required DLLs (compiler, wxWidgets, OpenCV including its own dependencies) are not anywhere in the PATH where the Windows can find them.
Yes it is, 222 MBytes. For the debug version until now because I compiled first the opencv debug version for testing if all things went well.As I wrote, linking complete OpenCV statically would probably result into an executable being several hundred megabytes large, is yours that big?
I did the same in all directions with alpha channel. It was tricky to find out but wxWidgets saves the alpha channel after the image channels that means RGB first in image file and then the alpha channel. Opencv uses BGRA. And for testing I wrote imshowAlpha() because imshow() displays the alpha channel in black but if you have a black image you will see nothing.BTW, I wrote an OpenCV bitmap to wxBitmap conversion function (does not support transparency): https://github.com/PBfordev/wxopencvtest
Next I will change the loading process for wxWidgets, as you described, after that I give some feedback and for opencv it is more tricky because they prevent compiling to some parts because of license issues. It is not easy to find out what went wrong in this case.
Thanks for your answers und Grüsse aus dem Schwarzwald
Re: Can not open images in windows
Hello,
with image.loadFile the image is loaded now I have to find out the opencv issue.
I will give feedback if it is solved.
with image.loadFile the image is loaded now I have to find out the opencv issue.
I will give feedback if it is solved.
Re: Can not open images in windows
All is functional now, wxWidgets and OpenCv, I can build static in Windows.
Thanks for your help!
Thanks for your help!
Re: Can not open images in windows
Hi,
What was the solution?
Ot might help someone else...
Thank you.
What was the solution?
Ot might help someone else...
Thank you.
Re: Can not open images in windows
The solution was to find out the correct settings to compile opencv with gcc on windows.
I will write a little documentation how to setup opencv using the same gcc compiler as pb used in his guide. If it is finished I will give feedback.
I will write a little documentation how to setup opencv using the same gcc compiler as pb used in his guide. If it is finished I will give feedback.
Re: Can not open images in windows
Assuming you mean static linkage here; considering the OpenCV dependencies (which may have its own dependencies, just think of FFMPEG alone), this looks quite tricky.
Moreover, there may be issues with libraries used by both OpenCV (or its dependencies) and wxWidgets (e.g., libtiff, libjpeg, libpng, zlib), unlike when using a prebuilt MSYS2 package using their system versions...