Printing GUID to screen - C++
Posted: 09 September 2010 06:04 AM   [ Ignore ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

Hi everybody,
I’m pretty new to c++ and have been trying to get my head around the SDK (slowly but surely ill understand what im doing).

so far I’ve managed to get the camera count to cout to the console, however I’m having difficulty with printing the guid to screen. I think its something to do with the variable type. Can anyone help me with this. I’m trying to get to grips with C++ so excuse my newbie understanding, gotta start somewhere.

Any help is appreciated!!

#include "stdafx.h"
#include "CLEyeMulticam.h"
#include "highgui.h"
#include "cv.h"
#include <iostream>

int main()

    
    cout 
<<"There are "<< CLEyeGetCameraCount()<<" cameras connected."<<endl;
    
cout << CLEyeGetCameraUUID(1)<<;

    
cin.get();
    return 
0;
Profile
 
 
Posted: 10 September 2010 03:16 AM   [ Ignore ]   [ # 1 ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

SOLVED!!

After a bit of thinking and tearing my hair out. Here is the function I created which I got from the CLEyeMulticam Test.cpp file. made a few alterations so it can work independently. The code was all there, guess it took me a while to figure out what the heck was going on.

void getGuid()
{
for (int i=0i<CLEyeGetCameraCount()+1i++)
    

        cout 
<<"Camera "<<i<<":"<<endl;
        
GUID guid CLEyeGetCameraUUID(i);
        
printf("Camera %d GUID: [x-x-x-xx-xxxxxx]\n"
                        
i+1guid.Data1guid.Data2guid.Data3,
                        
guid.Data4[0]guid.Data4[1]guid.Data4[2],
                        
guid.Data4[3]guid.Data4[4]guid.Data4[5],
                        
guid.Data4[6]guid.Data4[7]);

    
}
Profile
 
 
Posted: 12 September 2010 06:43 PM   [ Ignore ]   [ # 2 ]
New Member
Rank
Total Posts:  1
Joined  2010-09-12

Louis Vuitton cabas rivington, owing to its travel philosophy, makes every handbag simple, exquisite and comfortable. Simplicity yet exquisiteness is exactly what HandbagsModa.com is trying to present in its Louis Vuitton handbags section while maintaining the top quality of every LV replica.


HandbagsModa.com is the best online store ever providing all the top quality cheap designer handbags from Louis Vuitton cabas rivington,Gucci New Jackie, Hermes and Prada, where you can find the latest Louis Vuitton and Gucci releases, the most up-to-date sales events, the lowest prices at the same or even better grades and the kindest treat from designers like Louis Vuitton, Gucci, Hermes and Prada.

Profile
 
 
Posted: 13 September 2010 10:05 AM   [ Ignore ]   [ # 3 ]
New Member
Rank
Total Posts:  21
Joined  2010-03-26

This is a c++ way to do it. It’s not the most beautiful, but mixing printf and cout is definitely worse.

#include <iomanip>
#include <sstream>

/// Returns a hex-representation of an integral type variable
template <typename T>
std::string toHex(const Tinint width=2*sizeof(T))
{
    std
::ostringstream strstr;
    
strstr << std::hex << std::setfill('0') << std::setw(width) << in;
    return 
strstr.str();
}

// Composes a string from a GUID structure
inline std::string toString(const GUIDid)
{
    
return
         
toHex(id.Data1)+"-"+toHex(id.Data2)+"-"+toHex(id.Data3)+"-"
        
+toHex((int)id.Data4[0],2)+toHex((int)id.Data4[1],2)+"-"
        
+toHex((int)id.Data4[2],2)+toHex((int)id.Data4[3],2)
        +
toHex((int)id.Data4[4],2)+toHex((int)id.Data4[5],2)
        +
toHex((int)id.Data4[6],2)+toHex((int)id.Data4[7],2)
        ;
Profile
 
 
Posted: 13 September 2010 10:19 AM   [ Ignore ]   [ # 4 ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

Thanks for the feedback!

I didn’t ever remember using printf. my code looks like a bit of a hash at the moment and could definitely do with a good tidy up. would this be a direct replacement of the function above? Any chance you be able to break down what the bits of it all do? I’m slowly getting to grips with C++ after a tiny amount of exposure to it a few years back, so any further explanation would be great.

Hopefully ill have something to offer this forum when I improve!

Profile
 
 
Posted: 13 September 2010 11:14 AM   [ Ignore ]   [ # 5 ]
New Member
Rank
Total Posts:  21
Joined  2010-03-26

I suppose it’s a bit overkill with templates and streams if you’re new to c++.
Anyway, this is how to use it.

GUID guid CLEyeGetCameraUUID(i);
std::string guid_str=toString(guid); 
Profile
 
 
Posted: 13 September 2010 12:48 PM   [ Ignore ]   [ # 6 ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

I just had a go implementing the code: i put the bulk of the code into its own CPP file and used the two lines to call the ?function? but i got this error:

error C3861'toString'identifier not found 

I’d immediately point to it being a lack of forward declaration, but wasn’t sure what/how to declare it properly. I know it doesnt nest in a function, and yeah, i think templates and streams sound pretty good, but might be beyond my current abilities. I think Ill need to head down to the library and get a few books to help me along.

any books, or websites you might recommend?

thanks

Profile
 
 
Posted: 13 September 2010 01:58 PM   [ Ignore ]   [ # 7 ]
New Member
Rank
Total Posts:  21
Joined  2010-03-26

sorry about the confusion. since i already posted, i guess i’ll have to explain

template functions actually go into header files, since code will be generated for them wherever they are called (you should name those files *.hpp or *.hxx instead of just *.h to make it clear).

as a test you can define any function in a header file as “inline” (no need for the cpp file then), so you won’t need to worry about linking/declarations. it’s not the best way to do it, but it might save you some frustration in the beginning.

since you will probably call those functions only once in your whole app, an even easier solution is to define them locally in the cpp file where you call them (above the place where you call them). no need for a declaration since you will not call them from anywhere else. it’s acxtually what i did: i copied the code from a class CLEyeCamera with a std::string m_guid member. i never actually convert a guid to string, except in the constructor of that class.

also the implementation i copied in here is just a quick hack to avoid using any other library. it’s kinda complicated for what it does.

Profile
 
 
Posted: 14 September 2010 08:01 AM   [ Ignore ]   [ # 8 ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

I’m definitely going to give this all a go. I think I’m going to implement this as a *.hpp file and use it as a debug function. I plan on using multiple cameras, so it would be good to see which cameras are connecting/being initialised and when. I always find its a good idea to keep these bits separate from the main code as it keeps things tidy and I’m less likely to accidentally edit it or delete it if the file isn’t open.

I was wondering, if I were to create a function to compare a hard coded list of GUIDs would it be best to store the hard coded list as a GUID type or as a string?
If I stored them as a string, I could effectively compare the return from the function above with the hard coded list?

I might be well off the mark. What do you suppose would be the most effective solution to do this?

Profile
 
 
Posted: 14 September 2010 09:19 AM   [ Ignore ]   [ # 9 ]
New Member
Rank
Total Posts:  21
Joined  2010-03-26

Frankly, I don’t know.

I have the GUIDs for the cameras stored in a text file, ie. I also store and compare them as std::string because it’s simple. I always use lowercase, but that’s something to be careful about. It should also be possible to compare GUIDs just with operator ==

Profile
 
 
Posted: 19 September 2010 12:36 PM   [ Ignore ]   [ # 10 ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

Thanks for all your help aaichert!

I’m just trying to plan ahead. So i may not even need to check for this, but incase i do, ill know what im doing smile

thanks again.

Profile
 
 
 
 


RSS 2.0     Atom Feed