I'm having trouble loading joint data information from 'animation' node of collada file.
First, I try to load joints from 'library_visual_scenes' :
The first 2 joints look like that :
<visual_scene id="" name="">
<node name="joint1" id="joint1" sid="joint1" type="JOINT">
<translate sid="translate">0.000000 -2.000000 0.000000</translate>
<rotate sid="jointOrientZ">0 0 1 90.000000</rotate>
<rotate sid="rotateZ">0 0 1 0.000000</rotate>
<rotate sid="rotateY">0 1 0 0.000000</rotate>
<rotate sid="rotateX">1 0 0 0.000000</rotate>
<scale sid="scale">1.000000 1.000000 1.000000</scale>
<extra>
<node name="joint2" id="joint2" sid="joint2" type="JOINT">
<translate sid="translate">2.000000 0.000000 0.000000</translate>
<rotate sid="rotateZ">0 0 1 0.000000</rotate>
<rotate sid="rotateY">0 1 0 0.000000</rotate>
<rotate sid="rotateX">1 0 0 0.000000</rotate>
<scale sid="scale">1.000000 1.000000 1.000000</scale>
<extra>
which went well !
Maya joints :
My joints :
I would like to put a picture but as a new member, i'm not allowed. You'll have to trust me on this case, in my engine, joints are in the same place as in maya.
Then, I try to load joints from 'animation' node. Here is the problem, I can't find any jointOrient.
<animation id="joint1-anim" name="joint1">
<animation>
<source id="joint1-translate.Y-output">
<float_array id="joint1-translate.Y-output-array" count="2">-2.000000 -2.000000</float_array>
<animation>
<source id="joint1-rotateZ.ANGLE-output">
<float_array id="joint1-rotateZ.ANGLE-output-array" count="2">0.000000 0.000000</float_array>
<animation id="joint2-anim" name="joint2">
<animation>
<source id="joint2-translate.X-output">
<float_array id="joint2-translate.X-output-array" count="2">2.000000 2.000000</float_array>
So after loading joints, they look like that :
Anybody here could help ?
Thanks.
(Sorry as I don't have more than 10 reputations, i'm not allowed to put pictures.)
I finally figured out the answer, for those who might be interested.
The visual_scene node from collada will give you the bind pose for your joints.
So, I'm going to load visual_scene joint coordinates in a structure :
Something like that :
struct Pose
{
vec3 translation,
orientation,
rotation,
scale;
};
Pose bind_pose;
Then I'm going to create another instanciation of "Pose" struct, with a constructor which take a Pose as parameter :
Pose anim_pose(bind_pose);
So after construction, bind_pose from visual_scene and anim_pose are the same.
Then I'm going to iterate through all the animation node in library_animations, find the channel and get interested with :
the source data, which tell where to find joint animations info ("n" float(s) for "n" animation(s) :))
and the target joint.
<channel source="#joint1-translate.X" target="joint1/translate.X"></channel>
This tell us (and that's where I was a little lost) that we are going to REPLACE the targeted value with the source value.
If the source data find in channel node is the same as the target data, ie. :
bind_pose.translation.x has -3.0 as a value after loading visual_scene data, and
<source id="joint1-translate.X-output">
<float_array id="joint1-translate.X-output-array" count="1">-3.000000</float_array>
I do nothing.
If the source data is different from the target data, I simply replace in anim_pose with the good value.
And that's pretty much all you have to do to properly load animated joints from collada.
If you see anything wrong here, please tell me.
Hope this will help.
Related
The C++ function is:
Moments moments(InputArray array, bool binaryImage=false )
The first one I understand what it is, for the second one it says:
binaryImage – If it is true, all non-zero image pixels are treated as
1’s. The parameter is used for images only.
What does this mean exactly? I say it's true for binary images only and false for non-binary images? In my application I use a binary image to calculate simple moments.
It means that if this value is true the image you insert will be treated as it is a binary image meaning that even if you have values that are bigger than 1 they will be treated as 1.
I(x,y) > 0 = 1
I(x,y) == 0 = 0
If the value you insert is false than the values in the moments will take the real value into the moments calculation.
For example lets say you have the following 3X3 image:
100 0 10
10 0 1
0 0 0
m00 which is the area of the image will be:
If the flag is true than we have 4 pixels that are non zero and the value will be 4.
If the flag is false we will have 100+10+10+1 = 121
When should you use what?
Lets say we have a blob in our image.
If we treat the image as binary than the moments will give us spatial information about the blob.
For example m01/m00 and m10/m00 will give ust the center of mass of the object.
But if we treat the image not as binary we than moments will give us texture/color information.
For example m00/(number of pixels in the blob) = the mean color of the blob.
I'm working with openCV SVM in Visual Studio. (OpenCV 2.4.4.0)
I trained it:
mySVM.train(trainingDataMat, labelsMat, Mat(), Mat(), params);
Saved it:
mySVM.save("classifier.xml");
I'm loading it like this:
CvSVM mySVM1;
mySVM1.load("C:\classifier.xml");
mySVM1.predict(testingDataMat0,result0);
And i want to use in other project. But when i try to load classifier this error bumps all the time:
"Bad argument (The SVM should be trained first) in CvSVM::predict"
Path is correct, and .xml seems correctly stored.
Does anybody know what am I doing wrong or where the problem might be?
classifier.xml:
<?xml version="1.0"?>
<opencv_storage>
<my_svm type_id="opencv-ml-svm">
<svm_type>C_SVC</svm_type>
<kernel><type>RBF</type>
<gamma>5.0625000000000009e-001</gamma></kernel>
<C>2.5000000000000000e+000</C>
<term_criteria><epsilon>2.2204460492503131e-016</epsilon>
<iterations>100</iterations></term_criteria>
<var_all>3</var_all>
<var_count>3</var_count>
<class_count>2</class_count>
<class_labels type_id="opencv-matrix">
<rows>1</rows>
<cols>2</cols>
<dt>i</dt>
<data>
-1 1</data></class_labels>
<sv_total>10</sv_total>
<support_vectors>
<_>
9.09866020e-002 5.56291997e-001 2.43510995e-002</_>
<_>
9.46519971e-001 2.94328004e-001 2.08841003e-002</_>
<_>
1. 3.68389994e-001 1.15272999e-002</_>
<_>
9.41470027e-001 3.73109013e-001 1.25126000e-002</_>
<_>
1. 2.23776996e-001 9.57737025e-003</_>
<_>
4.68845010e-001 3.62690985e-002 9.11400989e-002</_>
<_>
7.98106015e-001 2.73550004e-002 9.26491022e-002</_>
<_>
7.02144980e-001 3.98130007e-002 9.00894031e-002</_>
<_>
4.99359012e-001 4.31513004e-002 8.61563012e-002</_>
<_>
7.39947975e-001 4.39946018e-002 9.60593969e-002</_></support_vectors>
<decision_functions>
<_>
<sv_count>10</sv_count>
<rho>-5.7845965027809154e-001</rho>
<alpha>
2.5000000000000000e+000 2.5000000000000000e+000
1.4641912158132706e+000 2.5000000000000000e+000
2.5000000000000000e+000 -1.4641912158132708e+000
-2.5000000000000000e+000 -2.5000000000000000e+000
-2.5000000000000000e+000 -2.5000000000000000e+000</alpha>
<index>
0 1 2 3 4 5 6 7 8 9</index></_></decision_functions></my_svm>
</opencv_storage>
I had this problem and found that in SVM codes ,at least in OpenCV, predict function uses the same kernel witch is used in train function to determine input class. So when you run predict separately it doesn't know what kind of kernel should it uses. So, I think running train function exactly before predict function is avoidable.
I am parsing a Collada file for animations. I have it drawn and animated fine but the issue now is how to setup the texture coordinates. I feed it to OpenGL exactly how the collada dae file gives it to me but its mapped completely wrong. The coordinates are range from [0-1].
Do I have to rearrange it?
If I do then please explain to me on how to go about it. I tried using GL_LINEAR and GL_NEAREST but it doesn't solve the problem. Any ideas why?
The models that I am using is the AstroBoy that http://www.wazim.com/Collada_Tutorial_1.htm gives and the Amnesia Servant Grunt.
Based on how you said it turns out to be mapped completely wrong, I'm guessing you haven't taken into account the the texture index values. I had a similar problem as well (although with a difference model). Just like you can have an array of index values so that OpenGL knows which order to draw the verticies, so to does Collada assign UV index values (and normal index values), and, annoyingly, they are never in the same order. Take the following Collada sample for instance:
<source id="Box001-POSITION">
<float_array id="Box001-POSITION-array" count="1008">
-167.172180 -193.451920 11.675772
167.172180 -193.451920 11.675772 .....
....
....
<source id="Box001-Normal0">
<float_array id="Box001-Normal0-array" count="5976">
-0.000000 -0.025202 -0.999682
-0.000000 -0.025202 -0.999682 .....
....
....
<source id="Box001-UV0">
<float_array id="Box001-UV0-array" count="696">
0.000000 0.000000
1.000000 0.000000
0.000000 1.000000 .....
....
....
<triangles count="664" material="_13 - Default">
<input semantic="VERTEX" offset="0" source="#Box001-POSITION"/>
<input semantic="NORMAL" offset="1" source="#Box001-Normal0"/>
<input semantic="TEXCOORD" offset="2" set="0" source="#Box001-UV0"/>
<p> 169 0 171 170 1 172 171 2 173 171 3
173 168 4 170 169 5 171 173 6 175 174
7 176 175 8 177 175 9 177 172 10 174 173 11 175 108 ....
The first three sections indicate the values of the verticies/normals/texture-coords but the final section indicates the index of each value. Notice how the first vertex index is 169, but the first normal index is 0. In fact, the normal indicies are completely normal, they progress as "0..1..2..3" but the indicies for the verticies and textures are all over the place! You have to order your vertex and texture values in the way the Collada file spcifies.
The other way is to write a little program that parses the collada file and rearranges all your vertex, normal and UV values into the right order based on the index values. Then you can just feed your points straight into OpenGL no questions asked. It's up to you of course, which way you want to handle it.
(PS: If you can make a good parser for Collada files, then the 'interleaved-indexing' is actually quite handy, if not though, I find it an over-complication on Collada's part, but you can't really do anything about it.)
No, I advice you to read some basic knowledge of collada .
<triangles count="664" material="_13 - Default">
<input semantic="VERTEX" offset="0" source="#Box001-POSITION"/>
<input semantic="NORMAL" offset="1" source="#Box001-Normal0"/>
<input semantic="TEXCOORD" offset="2" set="0" source="#Box001-UV0"/>
<p> 169 0 171 170 1 172 171 2 173 171 3......
the 169 is the first point index of a triangles,the 0 is the first normal index ,and the 171 is the first texcoord index ,and so on .
I'm struggling to see how I should use material and lighting values obtained from 3DS Max to recreate similar lighting. I am taking the material and lighting from a Collada file exported from 3DS Max and using them to render a scene in OpenGL. The scene is rendered using a Blinn-Phong shader. However the scene always ends up way to bright.
The light data from 3DS max seems quite odd to me. It consists of two lights, an ambient light and a directional light which only has a single colour. As I was not quite sure what this single colour relates to I've applied it to both the diffuse and specular components of the light.
Anyways, does anyone know if there is something odd with the 3DS Max/Collada material and lighting data? Or have you used it successfully with no problems meaning that I'm simply doing something wrong?
Edit #1
As requested, heres the material/lighting info from collada. I'm afraid I cannot post any screenshots, however the scene is coming out painfully bright, e.g Oranges becoming bright yellow. The specular values in particular seem very high, yet they seem to work fine in Max...
Collada Material:
<library_effects>
<effect id="WorldTexture">
<profile_COMMON>
<newparam sid="world_texture_png-surface">
<surface type="2D">
<init_from>world_texture_png</init_from>
</surface>
</newparam>
<newparam sid="world_texture_png-sampler">
<sampler2D>
<source>world_texture_png-surface</source>
</sampler2D>
</newparam>
<technique sid="common">
<blinn>
<emission>
<color>0 0 0 1</color>
</emission>
<ambient>
<color>0.588 0.588 0.588 1</color>
</ambient>
<diffuse>
<texture texture="world_texture_png-sampler" texcoord="CHANNEL1"/>
</diffuse>
<specular>
<color>0.9 0.9 0.9 1</color>
</specular>
<shininess>
<float>10</float>
</shininess>
<reflective>
<color>0 0 0 1</color>
</reflective>
<transparent opaque="A_ONE">
<color>1 1 1 1</color>
</transparent>
<transparency>
<float>1</float>
</transparency>
</blinn>
</technique>
</profile_COMMON>
<extra>
<technique profile="OpenCOLLADA3dsMax">
<extended_shader>
<apply_reflection_dimming>0</apply_reflection_dimming>
<dim_level>0</dim_level>
<falloff_type>0</falloff_type>
<index_of_refraction>1.5</index_of_refraction>
<opacity_type>0</opacity_type>
<reflection_level>3</reflection_level>
<wire_size>1</wire_size>
<wire_units>0</wire_units>
</extended_shader>
<shader>
<ambient_diffuse_lock>1</ambient_diffuse_lock>
<ambient_diffuse_texture_lock>1</ambient_diffuse_texture_lock>
<diffuse_specular_lock>0</diffuse_specular_lock>
<soften>0.1</soften>
<use_self_illum_color>0</use_self_illum_color>
</shader>
</technique>
</extra>
</effect>
Collada Lights:
<library_lights>
<light id="EnvironmentAmbientLight" name="EnvironmentAmbientLight">
<technique_common>
<ambient>
<color>0.6235294 0.6235294 0.6235294</color>
</ambient>
</technique_common>
</light>
<light id="FDirect001-light" name="FDirect001">
<technique_common>
<directional>
<color>0.937255 0.7921569 0.5411765</color>
</directional>
</technique_common>
<extra>
<technique profile="OpenCOLLADA3dsMax">
<max_light>
<aspect_ratio>1</aspect_ratio>
<atmosphere_color_amount>1</atmosphere_color_amount>
<atmosphere_on>0</atmosphere_on>
<atmosphere_opacity>1</atmosphere_opacity>
<attenuation_far_end>100</attenuation_far_end>
<attenuation_far_start>80</attenuation_far_start>
<attenuation_near_end>26.8</attenuation_near_end>
<attenuation_near_start>0</attenuation_near_start>
<contrast>0</contrast>
<decay_falloff>40</decay_falloff>
<decay_type>0</decay_type>
<diffuse_soften>0</diffuse_soften>
<falloff>902</falloff>
<hotspot_beam>900</hotspot_beam>
<multiplier>0.5</multiplier>
<overshoot>0</overshoot>
<shadow_density>1</shadow_density>
<shadow_map>0</shadow_map>
<target_distance>440</target_distance>
<use_far_attenuation>0</use_far_attenuation>
<use_near_attenuation>0</use_near_attenuation>
</max_light>
</technique>
</extra>
</light>
</library_lights>
Here is the example style I am using:
<?xml version="1.0" encoding="UTF-8"?>
<frameChart is3D="false">
<frame xDepth="3" yDepth="1" leftAxisPlacement="Back" isHStripVisible="true">
<background minColor="#FDFEF6"/>
</frame>
<yAxis scaleMin="1" scaleMax="500">
<labelFormat pattern="#,##0.###"/>
<parseFormat pattern="#,##0.###"/>
</yAxis>
<legend>
<decoration style="None"/>
</legend>
<elements place="Default" shape="Line" drawShadow="true">
<morph morph="Grow"/>
</elements>
</frameChart>
The above code will show 0 instead of 1.
This seems to be a common problem using cfchart, but it appears to be a problem in the web charts program as well.
Does anyone have a good solution?
Short answer: It is possible, but there are some side effects in your specific case.
Longer answer:
You can force the y-axis to start at 1 by specifying the number of labels (ie grid lines). But as long the range is an odd number (ie 500 - 1 ==> 499) some of the y-axis values may not line up evenly.
<!--- labelCount is number of grid lines + 1 --->
<yAxis scaleMin="1" scaleMax="500" labelCount="6">
<labelFormat style="Integer" pattern="#,##0"/>
</yAxis>
That is because y-axis values are calculated by dividing the scale range by the number of grid lines. With odd ranges that typically produces fractional numbers. For example, if you generated five (5) grid lines, the axis values would be:
Actual => Rounded Value
500.0 => 500
400.2 => 400
300.4 => 300
200.6 => 201 **
100.8 => 101 **
1.0 => 1
The only way to have complete control over all y-axis values is to ensure the range / grid lines works out to a whole number.