Noo! i wrote soo much and when i clicked reply it said too long and then i didn't get to copy it i have to write it again.
here we go again.
Hi,
I don't know a lot about what you are doing here (am flying by the seat of my pants), I had a quick read of the opencv documentation, but I am confused.
One small thing first If PtInRect returns a bool, there is no need to compare to 1, just do this:
if( PtInRect(projectedpoints[0].x,projectedpoints[0].y) )
|
fine, will do.
I am confused by Lines 1 to 7 in your code: There is more than 1 z value for each x,y value. If lenz is 10 say, there will be 10 z values for each x,y point - how does that work with the transformation on line 8? I would have expected 1 z value for each x,y point
|
the loop is actually just generating the 3D points to use for the projectpoints function, so if i have a dimension of x=10, y=10, z=10
i want to generate the 3d points 0,0,0 0,0,1 all the way upto 9,9,9
should i do it reverse with x in the centre of the nested loops and z on the outside of the nested loops.
Once you do the transformation, you have a 2D array of floats - how were you expecting those to be 0 or 255 unsigned values? Something to do with the camera matrix,
[/quote
they are 0 or 255 from the image segmentation process, which generated a mask made up of black and white elements, i didn't mention my mistake.
the camera parameters are the intrinsic, rot, tran in the projectpoints function.
[quote]I am guessing, but none the less projectedpoints is a 2D array of floats according to my reading of the documentation. So there will be problems with PtInRect as well - when I suggested that, I thought the points would be unsigned. |
i changed it to float x and float y in the function declaration.
Also, you are only sending 1 point to the projectPoints function (because you clear them both on lines 24 & 25), shouldn't you be sending all of them at once? So create your 3d points first, then send the whole thing to the projectPoints function.
Is this code for testing? Because you only test the very first value in projectedpoints. So the nested for loops are a bit pointless. In my mind, the call to projectPoints and the testing of its result should be outside the loops.
|
i was sending only one so i can generate only one and then i can process each one individually. i can try converting all the points and then process each one. will try
Line 13 still returns a float, so the comparison between it and an int won't work on line 14. Comparison with a float and 0.0 never works either because floats are stored as binary fractions.
|
so should i change it to
float check=0.0;
check = threedimension.at<float>(l,w,h);
if i can't use == operator for if(check==1) what else should i use.
So, a summary of what your code does:
- A threedpoint is created, presumably converting the 3 ints into floats. But no data value is assigned to the 3d coordinate. |
exactly, no data is stored at the 3d points, the only interest is the actual 3d coordinates.
- The projectPoints function is called, the result is in projectedpoints (a 2d array of floats) presumably this is supposed in the range (0.0,0.0) to (640.0,480.0)
- A check is made to see whether the projected point is in (0.0,0.0) to (640.0,480.0). There seems to be no copying of the data into a 640 by 480 array.
|
that is true, no change is made to the mask, only value of the pixel at the 2d coordinate is checked on the mask only.
- You then check a value in threedimension which looks like it has been initialised to 1.0's (floats), to see if it is 1 (int) - that comparison will always fail
|
correct, i check if it is 1, so i make check a float but how would i check if it is 1 or not.
- The original l, w, h float values are pushed into a new container vertexpoints.
- The value in the mask container is checked to see if it is 255 (int), but this was initialised with 0's (unsigned 8 bit) and it hasn't changed since then.
|
this mask was changed during the image segmentation process, which fills it with 255s or 0s.
- If that was true then the threedimension value is set to 0 (int), but threedimension is floats, but this seems to strangely have nothing to do with the projectedpoints container.
- The clear method is called for projectedpoints & threedpoint.
|
yup, it is set to zero if the value of the mask at the 2d coordinate is black. 0
So, some really confused ideas happening here. In my mind perhaps it should go like this:
> Create an array of data with a 3D point (1 z value for each x,y point) and a colour value. What is the value and type of the data at that 3d point? Is it an unsigned value representing a colour? Don't confuse it with the dimensions of the array.
|
3d points contain no data, only the 3d coordinates themselves are important.
> Transform the whole thing in one call to projectPoints. Make sure the transformation parameters are set up so that resulting projectedpoints produces 2d points in the range (0.0,0.0) to (640.0 480.0). Can use the PtInReact function here to check that it worked. Make sure that function works with floats - can't use the == operator. We needed float values for the coords in order to do the transformation, but the data itself (the colour) is still unsigned.
|
sure i can do that, but since i can't use the == operator to check for floats what can i use.
there is no colour value.
> Copy the value of the colour into the 640 by 480 image array - need to cast the 2d float coords in projectedpoints to unsigned 16 bit, to come up with the subscripts in the image array.
|
no change is necessary to be performed on the 640 by 480 image array as it is only for referencing.
> Must have some way of deciding whether a value is 0 or 255, not sure whether this happens in the projectPoints call, or whether the colour value doesn't change. If not you should write your own function to do that.
|
this happens in this code
if(int(mask.at<uchar>(projectedpoints[0]))==255)
As I said at the start, I don't have any experience with what you are doing - I don't know the details of the library, but I do know about co-ord transformation, and I think I have managed to figure out what you are wanting to do. But if I have any of it backwards or inside out - let me know :+) |
You got a good guess i just didn't explain myself, so i have included more info so hopefully it should help you and give tip based on those info.
so what my code does
mask is generated previously from image segmentation function and a binary image made up of 255s and 0s is generated this is before the for loop i have added.
then x,y,z corners are generated and is fed into the project points function, the 2d point is used as a coordinate to be used on the mask to see if it is a black or white element.
also 3d array element checked if it is a one or a zero, if one and the mask is a black element the 3d array is assigned zero and this is repeated for all the 3d coordinates.
thanks
;)