|
Hi. my program has ANSI multibyte compilated and uses several Unicode data sources. To convert Unicode to multibyte I use the folowing code:
WideCharToMultiByte(CP_ACP,WC_NO_BEST_FIT_CHARS,sUnic,numb_chars,ansi_buf,numb_chars,NULL,NULL);
This conversion works very fine in All code pages, but on Chinese systems dont works correctly - several characters from end of source unicode string is not converted. Please make happy our chinese clients! Thanks.
|
|
|
|
|
You are using the value numb_chars for the length of both buffers, but that may not be the case. You should use the following sequence to ensure you have enough space for the multibyte string:
int nMBChars;
nMBChars = WideCharToMultiByte(CP_ACP,WC_NO_BEST_FIT_CHARS,sUnic,numb_chars,NULL,0,NULL,NULL);
PTSTR ansi_buf = new TCHAR[nMBChars + 1];
int nMBConv = WideCharToMultiByte(CP_ACP,WC_NO_BEST_FIT_CHARS,sUnic,numb_chars,ansi_buf,nMBChars,NULL,NULL);
See here[^] for full details.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Thanks, Richard! You example code works fine!
|
|
|
|
|
Hi All
I m trying to develop MDI Application in explorer view.
Left side contains a tree view
Right side contains a dialog that will be open when a user clicks on a value in tree view.
Can Anyone provide a tutorial on this ...
Regards
Gany
|
|
|
|
|
That sounds more like a splitter than MDI. If you are using MFC then the CSplitterWnd[^] class should help you. Take a look at the articles here on CodeProject for potential samples.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
|
Hi
Thanks for the info.
But is tutorial is any available to start with ???
consider me as a begineer.
Regards
Gany
|
|
|
|
|
Hi
Any ways to help me>?
Regards
Gany
|
|
|
|
|
I am unsure If I am using my #include directives correctly and where to define my structures.
I have many files that are project independent, a .c and .h and when I want the features I have written in my main.c I #include feature.h as normal. What I wonder is I declare all of the includes that feature needs in its header and sometimes I have another include of the same file in another feature.h as well as my main.c
I know that the compiler is invoked for every separate c file so it will include say function _delay() in every .c file. The linker then puts all the objects together and makes the binary but does it strip the duplicate _delays?? I know the pragma once and other inclusion guards are only relative to that source file being compiled and each source will include the functions.
Along the same lines I have a enum states{Info = 0, Speed = 1}; declared in my header and want to use these states in multiple source files so I include the header when I need it. I also have an initialized structure struct branch the_table[8][5] = { {Control,0,0,0,0,0}, {Speed,0,0,0,0,0} }; and since this structure is using memory I must put it in my source file the problem is I want to be able to access this array outside of its source file and if I declare extern truct branch the_table[8][5]; in the header with the rest of the structure decelerations other source files cannot access its internal structure.
Can someone give some insight onto multiple inclusions upon linking and how to properly declare previously defined structures?
|
|
|
|
|
Trevor Johansen wrote: I know that the compiler is invoked for every separate c file so it will include say function _delay() in every .c file. The linker then puts all the objects together and makes the binary but does it strip the duplicate _delays?? I know the pragma once and other inclusion guards are only relative to that source file being compiled and each source will include the functions.
There is no need to strip the duplicates because there aren't actually duplicate functions (you may include the function declaration in all C source files, provided the function definition -i.e. the function body- is in just one source file).
Trevor Johansen wrote: declared in my header and want to use these states in multiple source files so I include the header when I need it. I also have an initialized structure struct branch the_table[8][5] = { {Control,0,0,0,0,0}, {Speed,0,0,0,0,0} }; and since this structure is using memory I must put it in my source file the problem is I want to be able to access this array outside of its source file and if I declare extern truct branch the_table[8][5]; in the header with the rest of the structure decelerations other source files cannot access its internal structure.
That's the correct way to do it: define the structure in one source file and made it available to other source files using the extern declaration.
As far as you use the #pragma once (do GCC recognize it?) directive (or the oldie-goldie #ifndef ...) to avoid multiple inclusions, I see no problem in your approach.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ahh I see so my delay.c is compiled to its own object obviously so at link time file1.o and file2.o while both using _delay() get it from delay.o I could have figured that one out if I took the though process a bit deeper eh..
This extern setup is a pain in the butt. I have multiple structures in my files for example I have my menu system as:
enum states {
Info = 0,
Speed = 1,
Up = 2,
Down = 3,
Control = 4,
OnOff = 5,
CW = 6,
CCW = 7
};
struct branch {
enum states new_state:7;
int entry_action;
int action_a;
int action_b;
int action_c;
int exit_action;
};
These are in my header file and almost exclusive to that source file except as the project grew I now need to read branch data from a separate source file. In that file if I include the header I get multiple definition errors of struct branch. Moving that structure to the source and declaring extern struct branch; solves the error but now I cannot use the structure in other source files as it says its undefined.
|
|
|
|
|
If you define the struct variable in one source file and declare it extern in another one, then such variable is avalable in the latter (and the linker won't complain), for instance:
(common header)
struct Point
{
int x,y;
};
void init();
(first source)
#include "main.h"
Point centre={0,0};
void init()
{
centre.x=100;
centre.y=120;
}
(second source)
#include <iostream>
#include "main.h"
extern Point centre;
void out()
{
std::cout << "cente = {" << centre.x << ", " << centre.y << "}" << std::endl;
}
void main()
{
init();
out();
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks for the help. I was defining correctly but the way I was handling the data was what was causing me problems as well. All fixed now.
Another question though, are #define's project global? I would love to know if I can say write an LCD library and use my own defines and macros but not have them conflict with the users program. I seem to not be able to and thats why we are told to append the file/function name before the name.
I just didn't really want 50 defines prefixed with LCD_
|
|
|
|
|
#define is resolved by the preprocessor, before the compiler starts hence they are global (for all sources including the corrensponding header).
You may go the C++ way: use const or (enum ) for your constants and wrap them in a namespace.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I hope this question is not too basic for this forum but I have been working at this for a while now and need to get something working.
I would like to be able to place a bitmap in my IE window when predetermined web pages are accessed, detect mouse clicks etc in IE and have IE function normally for all other pages.
I program in C/C++ and already have an intermediate level of familiarity with visual studio 2005 and mfc and have looked into BHOs, COM, ATL and ActiveX and find myself a bit overwhelmed.
If someone could just lay out a road map for me of the essentials so that I know what study path to follow to get to the point where I can build the above add on I would greatly appreciate it. Please point me to any existing apps that you know of that may help as well.
Thanks in advance for any help.
|
|
|
|
|
|
Hi-
I have been trying to work out how to delete a single point from a quad tree and am having no luck at all. Below are the code snippets for delete the entire tree then my failed attempt at deleting a single point. If someone could explain what I am doing wrong I would appreciate it.
Deleting the entire tree:
qnode *
deleteTree (qnode * root)
{
int i = 0;
for (i = 0; i < 4; i++)
{
if (root == NULL)
return root;
if (root->children[i] != NULL)
{
free (root->children[i]);
deleteTree (root->children[i]);
if (root->leaf == TRUE)
{
free (root);
root->leaf = NULL;
}
root->children[i] = NULL;
root->leaf;
root->cx = NULL;
root->cy = NULL;
root->size = NULL;
}
}
}
Failed attempt to delete a single point:
qnode *
deleteP (qnode * root, int vx, int vy)
{
int i = 0;
if (root->px - 5 >= vx && vx <= root->px + 5 && root->py - 5 >= vy && vy <= root->py + 5)
{
if (root == NULL)
return root;
if (root->leaf == TRUE)
{
root->leaf = NULL;
free (root);
}
else
{
root->leaf = TRUE;
deleteP (root, vx, vy);
root->px = NULL;
root->py = NULL;
free (root);
}
}
}
Thank you for your time
|
|
|
|
|
First, you have bugs in your deleteTree implementation.
Chidori-chan wrote:
free (root->children[i]);
deleteTree (root->children[i]);
This is undefined behavior. Once you have freed the child node, it is no longer yours and you must not access it. Reverse the order of these two lines.
There are more problems in your deleteTree implementation as well. I will let you work on finding them.
Perhaps I am wrong here, but I would think that deleting a single point actually means deleting the entire subtree starting from that point. Otherwise, what do you do about all those would be orphaned nodes? So I expected to see a call to deleteTree somewhere in deleteP. I didn't find it.
Also, I would think that you need to traverse the tree to locate the point to be deleted. I would expect that to be the first thing you would have to deal with, but don't see it in your code.
Please do not read this signature.
|
|
|
|
|
Without fully understanding the code above I noticed a couple of things in the deleteTree() function:
if (root->leaf == TRUE)
{
free (root);
root->leaf = NULL;
}
You then continue using the root pointer.
The following statement is meaningless.
root->leaf;
In the following block in the deleteP() function:
if (root->leaf == TRUE)
{
root->leaf = NULL;
free (root);
}
there is no point in setting root->leaf to null, as you immediately free the object. Similarly in the else block you set two pointers to null immediately before freeing the object.
Also both functions have paths that do not return values, and thus should not compile.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Thank you all for your help, keeping your advice in mind I have come up with these functions and it kinda works. It will delete points only in a certain area of the screen..
int checkKids(qnode *parent)
{
int i;
for(i = 0; i < 4; ++i)
if(parent->children[i] != NULL)
return 0;
return 1;
}
void deletE(qnode *root)
{
if(checkKids(root) && !root->leaf)
{
root = NULL;
free(root);
}
else
{
int i;
for(i = 0; i < 4; ++i)
if(root->children[i] != NULL)
deletE(root->children[i]);
}
}
void deletePoint()
{
deletE(root);
}
void deletePointS (int sx, int sy, qnode *root)
{
int i;
for(i=0; i<4; i++)
{
if(root->children[i] != NULL)
{
if(root->children[i]->leaf == TRUE)
{
if(isIn(root->children[i]->px, root->children[i]->py, sx, sy, 5))
{
root->children[i] = NULL;
free(root->children[i]);
if(checkKids(root))
{
free(root);
root = NULL;
}
return;
}
}
else
{
deletePointS(sx, sy, root->children[i]);
}
}
}
}
void deleteNode (int sx, int sy)
{
int deleting;
if(deleting == 1)
return;
deleting = 1;
deletePointS(sx, sy, root);
deletePoint();
deleting = 0;
}
|
|
|
|
|
Hi there,
Does anyone know if there's a possibility to implement a fast translation-, rotation- and scalation-invariant Template Matching application in native C++.
I want to realize that task by using open-source libraries such as OpenCV and fftw.
I just read about techniques with log-polar transformations or circular/radial filters to find the template location, after that I may need some kind of cross-correlation?!
Has anyone other suggestions than that?
And which one would be the fastest?
I have to operate on realtime and I know, that this task is very computational intensive. But it's also ok to take a learning-phase with the template, in which some preparing computations can be done.
I have also the possiblity to work on a limited factor size in rotation and scalation (maybe +/-10%).
What would you recommend me to do or has anyone done a similar project?
Or are there some good open-source libraries to manage that?
I'd be happy about some suggestions! Thanks in advance!
cherry
|
|
|
|
|
I've been doing some work with OpenCV for about a year or so now. Not knowing exactly what you're trying to accomplish, the short answer is yes. What size images are you planning to work with and what frame rate do you consider "real time". Those are the two big tradeoffs with any image processing. I'd say from the description, you're not going to get anywhere near 30 frames a second for any reasonable sized images, especially with the FFT thrown in. At least on a standard PC.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Thanks for the quick answer! Sounds not too bad
My aim is to do a print quality inspection respective a defect detection on prints.
The images may surely be up to 800x600 pixels (also smaller).
I'll be working on RT VxWorks on an x86 Target. Nothing too special.
The quality inspection is done on i.e. business cards, label or something in bank note size.
I want to "learn in" a good template, to which following images are being compared.
Images are being acquired quickly from a camera and have to be matched as fast as possible.
I thought, if the search angle and the scale factor are limited, the computation can get pretty acceptable.
But I'm not sure which method to focus:
-The log-polar transformation seems interesting, but I'm not sure if that obtains acceptable computation times.
30 frames per second would be quite ok!
-Circular/Radial filter seems more complex and intensive and is maybe not the right approach here?!
In principle I do not have to find multiple templates in the images. I just want to relocate the inspection image to
fit to the template and then find out the defect pixels (correlation)! Just a little scalation has to be considered (5%).
Maybe template matching is the wrong approach because most template matching algorithms search for multiple occurences of
small objects.
Or am I though right with my thoughts?
bye, cherry
|
|
|
|
|
Sounds like a first pass would be doing some kind of difference score between the image and your template. I know OpenCV has some template matching functions but I've not played with them. Most of my time so far has been spent in building a framework to all me to quickly build test apps to try things and I spend a lot of time taking Gary's name in vain (along with Bill, Bjarne, and occasionally Julian). My applications are more related to SLAM for robotics.
It sounds like your images will be fairly consistent so I'd see if I could determine some easily detected points to use to determine orientation and scale without having to do anything too general. Then you can apply your matching method with a bit more confidence.
In one of my tests, I'm working with a 360x240 image and trying to isolate and locate an orange traffic cone. I think I'm getting about 20 frames a second on that. Of course, I'm doing a lot of display which takes some time that you might not have to do or could offload in an industrial setting.
OpenCV is great for prototyping and test but one of the drawbacks is that you end up sequentially performing some tasks that could be combined into one pass on the image so you get a bit of loop overhead that could be eliminated once you get it to work and gain some speed that way.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Yes, you're right. It's not necessary for me to find my template in a bigger image. I just thought about the fact you mentioned,
to find some simple objects on which I can relocate the image.
I know the OpenCV template matching functions, they do pretty well.
But they are only for translation invariant pictures, so I need something to find to rotation angle.
The OpenCV template matching only uses some correlation or square difference techniques. I only can use them
in the case my image is rotated the right way.
I also observed, that there's some optimization space in the OpenCV functions, as you said.
How did you locate the traffic cone? How did you find the rotation angle respective scaled cones?
I'd be happy if you could just tell me the keyword of the technique, something I could research...
For now, I only read about techniques of that log-polar stuff and similar things in frequency domain.
I wonder now if there could be another way to relocate the rotation/scalation.
So far, thanks Tim!
|
|
|
|
|