Save images in C++, without OpenCV

asked 2014-10-22 03:16:58 -0500

ringholm gravatar image

updated 2017-08-01 18:32:27 -0500

Hello. I know some might find this weird. I have a SoftKinetic DS311 camera, and we managed to get a LabVIEW interface somewhat working. It works by having modified a sample code to writing .txt files containing the depth info, LabVIEW then scans these files as strings.

The sample code is written in C++, and I would like to also access the color image. Usually I would use LabVIEW to access the camera, but I can't when the sample code is running (the USB is probably busy). So I would like to modify the C++ code to save an image while simoultaneously writing depth info. I would prefer to do so without having to install OpenCV, since this seems quite extensive for my needs. Cheers

edit retag flag offensive close merge delete



now , how is this related to opencv ?

berak gravatar imageberak ( 2014-10-22 03:29:09 -0500 )edit

Well, this is a forum for asking questions about opencv, not about not opencv.

Anyway, as I think you are a beginner in C++, I would recommend to use opencv in this case, if you want to save your image as JPG without hassles (see the imwrite function).

Otherwise you can use the libjpeg library. Search google for examples, but I wouldn't recommend it if you are absolute beginner.

BTW, I think it's better to save the depth data to a more compact lossless image format, like tiff instead of txt files.

kbarni gravatar imagekbarni ( 2014-10-22 03:30:29 -0500 )edit

If you do not wish use OpenCV, you should use a dedicated library targeted to load/save images (libjpeg, libpng, libfreeimage), and see how incorporate it to your code, pretty much as OpenCv does with its own code. Or maybe you should read the specifications of some format (maybe a simple one such as PPM/PGM) and implement it yourself.

R.Saracchini gravatar imageR.Saracchini ( 2014-10-22 03:39:12 -0500 )edit

I know, this is a weird place to post, but I figured that since you guys know a lot about computer vision, I thought the answer might be here. Yes, I am new to C++. For some reason I have to use Visual Studio 2008, otherwise I get errors when I build my solution. And it seems that OpenCV runs best on VS2010 and forth (or am I mistaken?) Regarding fileformat: again, I am new, and this was a way to make LabVIEW read the depth data :)

ringholm gravatar imageringholm ( 2014-10-22 03:39:40 -0500 )edit

If you are really in a pinch to write such images and do not want incorporate external libs to your code, write a function write such data in PPM/PGM format. It is very simple, and I always ask to my students (Programming I) to do that as exercise. Give a look in the specifications here:

As far I know, LabView can read such format later without any problems.

R.Saracchini gravatar imageR.Saracchini ( 2014-10-22 03:54:22 -0500 )edit

^^ voice of reason ;)

berak gravatar imageberak ( 2014-10-22 03:59:17 -0500 )edit

Okay, I decided to try OpenCV, However, do there exist an installing guide, where alle the links to all the additional packages and stuff that is required to work, are updated?

ringholm gravatar imageringholm ( 2014-10-22 04:29:23 -0500 )edit

there are prebuild opencv libs for windows , unfortunately, afaik, no more for vs2008. (2.4.6 was the last i've seen including those, but it's no more available. falling back to 2.3.1 is not recommended(too old))

so, with vs2008, you'd have to build opencv from src, using cmake. that's absolutely doable, but not for the faint of heart.

hmm, reconsider the ppm idea ? even for a n00b, it's more like 2 hours work vs. 2 days of frustration.

berak gravatar imageberak ( 2014-10-22 04:44:21 -0500 )edit

I did reconsider, however you never know if I would need it again in the future. And also the method of writing a .txt file for LabVIEW interpretation is a crude method - it works, but just barely. I actually have Visual Studio 2013. Do I just download and install or how does it work? Btw, I really appreciate you guys taking time to help me though!

ringholm gravatar imageringholm ( 2014-10-22 04:55:23 -0500 )edit

for vs2013, it's just download/unpack. (and setup include/library/bin paths)

(and stick with 2.4.9 or 2.4.10 for now. 3.0 might be too much adventure..)

berak gravatar imageberak ( 2014-10-22 05:03:26 -0500 )edit