![]() |
|
#1
|
|||
|
|||
OpenCv C to C++I want to adapt the c++ interface of Opencv but find it hard converting my codes from c to c++. Does anyone know the equivalent version of cvCreateImage in c++?
Thanks |
|||
|
#2
|
|||
|
|||
Re: OpenCv C to C++Quote:
With OpenCV version 1.0.0 on my Centos 5.8 workstation: CPP / C++ / C Code:
Compile with something like g++ -W -Wall -pedantic opencv_demo.cpp -lopencv_legacy -o opencv_demo Put an image file, say baboon.jpg, in the same directory, then execute ./opencv_demo baboon.jpg Regards, Dave Footnote: I have shown you mine; now show me yours. In other words: If you have a small C file that works for you and you have tried to convert to C++ and it didn't work, then post the code. Tell us the operating system, compiler and OpenCV versions that you are using. Here's the thing: For best chances of meaningful help with fewest iterations, give us complete information about your system and your requirements so that we can make a stab at trying to help you. Later versions of OpenCV have lots of C++ functionality above and beyond the C functions in version 1.0.0, but there is no way for us to guess at what your problems are. Also, there are examples in the OpenCV distribution and there are tutorials for recent versions on the OpenCV web site opencv.org Start at The OpenCV wiki __________________
Sometimes I just can't help myself... Last edited by davekw7x : 28-May-2012 at 08:55.
|
|
#3
|
|||
|
|||
Re: OpenCv C to C++This is the original c code that I want to convert to c++
CPP / C++ / C Code:
The code above converts a colored image into binary Here the c++ code that I got so far CPP / C++ / C Code:
And here's the error from the code above Code:
Specifications: Ubuntu 12.04 OpenCv 2.3 GNU g++ Last edited by admin : 30-May-2012 at 22:28.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|
#4
|
|||
|
|||
Re: OpenCv C to C++Its a really tough platform. the program which can be solved in 4 to 5 line, That can be solved in 100 lines mostly.
|
|
#5
|
|||
|
|||
Re: OpenCv C to C++Quote:
CPP / C++ / C Code:
Getting satisfactory results may require tweaking the threshold limits (depending on the image), but it can work. I hate to repeat myself, but it already is C++. Quote:
As far as the error messages, themselves: Code:
Now, you can eliminate the error message by simply changing the call to CPP / C++ / C Code:
However...there are still major problems that cause a malfunction. Namely. split is going to split the image into three planes, so the second argument must point to an array of three Mat objects, not just one object. (Note that another form of split takes a vector of Mat objects for its second argument.) Bottom line: If I were writing it, it might look the following. (But: see Footnote.) CPP / C++ / C Code:
Regards, Dave Footnote: Your use of split() followed by the calls to add() can result in limiting of the sum of r+g+b. Threshold will be very critical to prevent washout. If you just want to convert rgb to grayscale, you can use convertColor(). Then the entire function can be simplified: CPP / C++ / C Code:
Also, sometimes adaptiveThreshold(), rather than plain vanilla threshold(), might be appropriate. (Your Mileage May Vary.) On the other hand, if you had done it like this you might not have learned about the new split(), which is very useful for other transformations... __________________
Sometimes I just can't help myself... |
|
#6
|
|||
|
|||
Re: OpenCv C to C++Quote:
Actually, there is a further refinement. Back in olden times, when OpenCV stuff was written in C, things like cvCreateMat() were required to generate storage for cvMat "objects." Nowadays, we can just use the Mat constructor. (There is no need for the application program to release the storage, since the Mat destructor takes care of it when the object goes out of scope.) CPP / C++ / C Code:
Regards, Dave __________________
Sometimes I just can't help myself... |
|
#7
|
|||
|
|||
Re: OpenCv C to C++Thanks for your comments appreciate it.
And one more thing if I include Code:
then instead of doing this Code:
Is it the same thing or completely different things. I'm a total newbie when it comes to using opencv that's why I'm asking. Thanks |
|
#8
|
|||
|
|||
Re: OpenCv C to C++Quote:
In the Footnote of that same post (and in the complete program of my last post) I showed how to convert to grayscale without adding r+g+b, but sometimes you do want to add image components, and the add() function is a way to do it. Bottom line: All of the cvXXX functions are carryovers from older versions. Even though most of these "legacy" functions are more-or-less compatible, with more recent versions of OpenCv, in my opinion it's much better to learn how to use the cv namespace and use modern equivalents of those functions. Some of the functions don't have (and don't need) modern equivalents, as I mentioned in my last post. You don't need a function like cvCreateMat, since the constructor of the Mat class does the deed. You don't need anything like cvReleaseImage, since the Mat class destructor cleans up after itself. (Huzzah!) Here's the thing: OpenCV has never been particularly "easy" for (most) people to learn, but if you have needs for even a small part of the functionality, you might find it well worth the effort. My suggestion: Start with some explanations, tutorials and examples on the OpenCV web site. (There are also some examples in the OpenCV source download tree.) So, look at things like this on their web site: OpenCV Introduction Then... Click on the tutorials link on The OpenCV Documentation Page Regards, Dave __________________
Sometimes I just can't help myself... |
|
#9
|
|||
|
|||
Re: OpenCv C to C++Quote:
Thanks for your comment |
Recent GIDBlog
Running Linux Programs at Boot Time by gidnetwork
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Silhouette extraction algorithm from depth video | chezmark | Java Forum | 1 | 05-Dec-2011 00:40 |
| OpenCV and problems with matrices | ipunished | C++ Forum | 2 | 19-Jul-2011 10:58 |
Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The