I am fairly new to Mascript and Autodesk - I have a simple script, that places a camera and I want to change the FOV, horizontally and vertically.
I am using the example provided from Max-Script Documentation, and my script looks like the following:
rgb_cam = freecamera name: "foo" position:[0,0,0]
rgb_cam.fov Float default: 45.0
The second command gives me the error:
-- Type error: Call needs function or class, got: 45.0
-- MAXScript callstack:
-- thread data: threadID:8848
-- ------------------------------------------------------
-- [stack level: 0]
-- In top-level
So I guess, that the way the function is called is wrong, however the documentation said so.
Lastly, this will only change the horizontal fov, not the vertical one - how can I change it via MaxScript?
I am using Autodesk 3ds Max 2018 - Student Version
You just have to assign the value to the fov parameter, you do this like this:
rgb_cam = freecamera name: "foo" position:[0,0,0]
rgb_cam.fov = 33.0
What the documentation is telling you is that the fov defaults to 45 and is a float value, that line is not a valid piece of code.
I was able to find the solution by myself. The documentation is not how to execute the files, but merely showing how the default parameters are. Furthermore, one has to change the flag determining the actual chosen field of view settings, like this:
rgb_cam = freecamera name: "rgb" position:[0.0,0.0,25.0] rotation: (eulertoquat (eulerAngles 0 0 0))
--Horizontal FOV
rgb_cam.fovType = 1
rgb_cam.fov = 84.1
--Vertical FOV
rgb_cam.fovType = 2
rgb_cam.fov = 48.1
Related
I'm trying to add a slider in tool mode like this:
code:
tool
extends Position2D
export(float) var CustomSlider = 0.1 setget changeSlider_x
func changeSlider_x(changed_val):
CustomSlider=changed_val
First of all, I want to point out that this variable:
export(float) var CustomSlider = 0.1
Is a variant. Even thought Godot shows it as a float on the inspector panel.
This is a float and Godot will also show it as float in the inspector panel:
export var CustomSlider := 0.1
Or if you prefer the type to be explicit, you can write it like this:
export var CustomSlider:float = 0.1
What you specify between parenthesis after export is to controls how it will be shown in the inspector panel.
I know the documentation is a little hard to find - because there are other things called "export" - but here it is: GDScript exports
Now, to get a (useful) slider, you have to either:
Specify a range of values:
export(float, 0, 10) var CustomSlider:
Specify a range of values, with snapping to a step size:
export(float, 0, 10, 0.1) var CustomSlider:
The snapping will be to a multiple of the step size. That is, the snapping is not offset by the minimum and maximum.
Specify an exponential slider, with a maximum greater than zero (the minimum will be zero):
export(float, EXP, 10) var CustomSlider:
With this the slider is not linear. You will find that at the half point the value is the square root of the maximum, not the half. And a third of the way, you find the cubic root of the maximum, and so on. As a result, number are more tightly packed near the maximum (e.g. for a range from 0 to 100, the half point is 10, so the first half goes from 0 to 10 and the second half goes from 10 to 100).
Specify an exponential slider, with a minimum and a maximum:
export(float, EXP, 10, 100) var CustomSlider:
This is similar to the behavior above, except it is offset so the minimum is not zero, but the one you specified.
Specify an exponential slider, with a minimum, a maximum, and snapping to a step size:
export(float, EXP, 10, 100, 2) var CustomSlider:
This creates an exponential slider similar to the previous case. Except this one will snap the value, similar to the snapping described before.
Aside from using export, there is another way to have something show in the inspector panel: use _get_property_list (requires a tool script), which would give us more control (some options are only available this way). Furthermore, we could call property_list_changed_notify to tell Godot to check again what it should show in the inspector panel, and that would allow you to have it change dynamically.
By the way, you can write your variable name in lower caps and with _, and Godot will capitalize it and replace the _ with spaces when it shows it in the inspector panel.
I remember that is a function to calculate the differential/derivative for a line plot in a DM version, it looks lik in the process- non linear filter- derivative. But I do not remember which version has this function, any suggestion?
The UI functionality for spectral filtering is found in the Spectrum menu:
Since GMS 3 this functionality is part oft the free software, before it was part of the Spectroscopy license (any).
The menu only works on line profiles which are spectra, for which the Convert Data To menu would be used when required.
As all "menu" commands, you can access them using the ChooseMenuItem command as in:
GetFrontImage().SelectImage() // Make sure the image window is selected, or the menu is disabled if the script-window is frontmost!
ChooseMenuItem("Spectrum","Numerical Filters","First derivative")
The mathematical functions behind this menu are also available as (unofficial, undocumented) script commands. They do not use the preferences but the parameters directly, using uncalibrated 'channel' scale.
So you could also use:
image src := GetFrontImage()
number chWidth = 5 // The values matching the settings
number chDelta = 1 // The values matching the settings
number chShift = trunc((chWidth + chDelta)/2 + 0.5)
number norm = chWidth + chDelta
image fDev := src.FDeriv_Spectrum( chWidth, chShift, norm )
fDev.ShowImage()
Just be warned that there is no guarantee that the command FDeriv_Spectrum will be continued in future versions of GMS (It is not an officially supported command.)
Finally, the math of a first derivative are really simple, so you could just recreate the function with pure DM-script commands like offset and arithmetic operators.
A simple, non-smoothed 1-channel derivative would simply be:
image src := GetFrontImage()
image fdev := src - src.offset(-1,0)
fdev.ShowImage()
I have a set of images and want to make a cross matching between all and display the results using trackbars using OpenCV 2.4.6 (ROS Hydro package). The matching part is done using a vector of vectors of vectors of cv::DMatch-objects:
image[0] --- image[3] -------- image[8] ------ ...
| | |
| cv::DMatch-vect cv::DMatch-vect
|
image[1] --- ...
|
image[2] --- ...
|
...
|
image[N] --- ...
Because we omit matching an image with itself (no point in doing that) and because a query image might not be matched with all the rest each set of matched train images for a query image might have a different size from the rest. Note that the way it's implemented right I actually match a pair of images twice, which of course is not optimal (especially since I used a BruteForce matcher with cross-check turned on, which basically means that I match a pair of images 4 times!) but for now that's it. In order to avoid on-the-fly drawing of matched pairs of images I have populated a vector of vectors of cv::Mat-objects. Each cv::Mat represents the current query image and some matched train image (I populate it using cv::drawMatches()):
image[0] --- cv::Mat[0,3] ---- cv::Mat[0,8] ---- ...
|
image[1] --- ...
|
image[2] --- ...
|
...
|
image[N] --- ...
Note: In the example above cv::Mat[0,3] stands for cv::Mat that stores the product of cv::drawMatches() using image[0] and image[3].
Here are the GUI settings:
Main window: here I display the current query image. Using a trackbar - let's call it TRACK_QUERY - I iterate through each image in my set.
Secondary window: here I display the matched pair (query,train), where the combination between the position of TRACK_QUERY's slider and the position of the slider of another trackbar in this window - let's call it TRACK_TRAIN - allows me to iterate through all the cv::Mat-match-images for the current query image.
The issue here comes from the fact that each query can have a variable number of matched train images. My TRACK_TRAIN should be able to adjust to the number of matched train images, that is the number of elements in each cv::Mat-vector for the current query image. Sadly so far I was unable to find a way to do that. The cv::createTrackbar() requires a count-parameter, which from what I see sets the limit of the trackbar's slider and cannot be altered later on. Do correct me if I'm wrong since this is exactly what's bothering me. A possible solution (less elegant and involving various checks to avoid out-of-range erros) is to take the size of the largest set of matched train images and use it as the limit for my TRACK_TRAIN. I would like to avoid doing that if possible. Another possible solution involves creating a trackbar per query image with the appropriate value range and swap each in my secondary windows according to the selected query image. For now this seems to be the more easy way to go but poses a big overhead of trackbars not to mention that fact that I haven't heard of OpenCV allowing you to hide GUI controls. Here are two example that might clarify things a little bit more:
Example 1:
In main window I select image 2 using TRACK_QUERY. For this image I have managed to match 5 other images from my set. Let's say those are image 4, 10, 17, 18 and 20. The secondary window updates automatically and shows me the match between image 2 and image 4 (first in the subset of matched train images). TRACK_TRAIN has to go from 0 to 4. Moving the slider in both directions allows me to go through image 4, 10, 17, 18 and 20 updating each time the secondary window.
Example 2:
In main window I select image 7 using TRACK_QUERY. For this image I have managed to match 3 other images from my set. Let's say those are image 0, 1, 11 and 19. The secondary window updates automatically and shows me the match between image 2 and image 0 (first in the subset of matched train images). TRACK_TRAIN has to go from 0 to 2. Moving the slider in both directions allows me to go through image 0, 1, 1 and 19 updating each time the secondary window.
If you have any questions feel free to ask and I'll to answer them as well as I can. Thanks in advance!
PS: Sadly the way the ROS package is it has the bare minimum of what OpenCV can offer. No Qt integration, no OpenMP, no OpenGL etc.
After doing some more research I'm pretty sure that this is currently not possible. That's why I implemented the first proposition that I gave in my question - use the match-vector with the most number of matches in it to determine a maximum size for the trackbar and then use some checking to avoid out-of-range exceptions. Below there is a more or less detailed description how it all works. Since the matching procedure in my code involves some additional checks that does not concern the problem at hand, I'll skip it here. Note that in a given set of images we want to match I refer to an image as object-image when that image (example: card) is currently matched to a scene-image (example: a set of cards) - top level of the matches-vector (see below) and equal to the index in processedImages (see below). I find the train/query notation in OpenCV somewhat confusing. This scene/object notation is taken from http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html. You can change or swap the notation to your liking but make sure you change it everywhere accordingly otherwise you might end up with a some weird results.
// stores all the images that we want to cross-match
std::vector<cv::Mat> processedImages;
// stores keypoints for each image in processedImages
std::vector<std::vector<cv::Keypoint> > keypoints;
// stores descriptors for each image in processedImages
std::vector<cv::Mat> descriptors;
// fill processedImages here (read images from files, convert to grayscale, undistort, resize etc.), extract keypoints, compute descriptors
// ...
// I use brute force matching since I also used ORB, which has binary descriptors and HAMMING_NORM is the way to go
cv::BFmatcher matcher;
// matches contains the match-vectors for each image matched to all other images in our set
// top level index matches.at(X) is equal to the image index in processedImages
// middle level index matches.at(X).at(Y) gives the match-vector for the Xth image and some other Yth from the set that is successfully matched to X
std::vector<std::vector<std::vector<cv::DMatch> > > matches;
// contains images that store visually all matched pairs
std::vector<std::vector<cv::Mat> > matchesDraw;
// fill all the vectors above with data here, don't forget about matchesDraw
// stores the highest count of matches for all pairs - I used simple exclusion by simply comparing the size() of the current std::vector<cv::DMatch> vector with the previous value of this variable
long int sceneWithMaxMatches = 0;
// ...
// after all is ready do some additional checking here in order to make sure the data is usable in our GUI. A trackbar for example requires AT LEAST 2 for its range since a range (0;0) doesn't make any sense
if(sceneWithMaxMatches < 2)
return -1;
// in this window show the image gallery (scene-images); the user can scroll through all image using a trackbar
cv::namedWindow("Images", CV_GUI_EXPANDED | CV_WINDOW_AUTOSIZE);
// just a dummy to store the state of the trackbar
int imagesTrackbarState = 0;
// create the first trackbar that the user uses to scroll through the scene-images
// IMPORTANT: use processedImages.size() - 1 since indexing in vectors is the same as in arrays - it starts from 0 and not reducing it by 1 will throw an out-of-range exception
cv::createTrackbar("Images:", "Images", &imagesTrackbarState, processedImages.size() - 1, on_imagesTrackbarCallback, NULL);
// in this window we show the matched object-images relative to the selected image in the "Images" window
cv::namedWindow("Matches for current image", CV_WINDOW_AUTOSIZE);
// yet another dummy to store the state of the trackbar in this new window
int imageMatchesTrackbarState = 0;
// IMPORTANT: again since sceneWithMaxMatches stores the SIZE of a vector we need to reduce it by 1 in order to be able to use it for the indexing later on
cv::createTrackbar("Matches:", "Matches for current image", &imageMatchesTrackbarState, sceneWithMaxMatches - 1, on_imageMatchesTrackbarCallback, NULL);
while(true)
{
char key = cv::waitKey(20);
if(key == 27)
break;
// from here on the magic begins
// show the image gallery; use the position of the "Images:" trackbar to call the image at that position
cv::imshow("Images", processedImages.at(cv::getTrackbarPos("Images:", "Images")));
// store the index of the current scene-image by calling the position of the trackbar in the "Images:" window
int currentSceneIndex = cv::getTrackbarPos("Images:", "Images");
// we have to make sure that the match of the currently selected scene-image actually has something in it
if(matches.at(currentSceneIndex).size())
{
// store the index of the current object-image that we have matched to the current scene-image in the "Images:" window
int currentObjectIndex = cv::getTrackbarPos("Matches:", "Matches for current image");
cv::imshow(
"Matches for current image",
matchesDraw.at(currentSceneIndex).at(currentObjectIndex < matchesDraw.at(currentSceneIndex).size() ? // is the current object index within the range of the matches for the current object and current scene
currentObjectIndex : // yes, return the correct index
matchesDraw.at(currentSceneIndex).size() - 1)); // if outside the range show the last matched pair!
}
}
// do something else
// ...
The tricky part is the trackbar in the second window responsible for accessing the matched images to our currently selected image in the "Images" window. As I've explained above I set the trackbar "Matches:" in the "Matches for current image" window to have a range from 0 to (sceneWithMaxMatches-1). However not all images have the same amount of matches with the rest in the image set (applies tenfold if you have done some additional filtering to ensure reliable matches for example by exploiting the properties of the homography, ratio test, min/max distance check etc.). Because I was unable to find a way to dynamically adjust the trackbar's range I needed a validation of the index. Otherwise for some of the images and their matches the application will throw an out-of-range exception. This is due to the simple fact that for some matches we try to access a match-vector with an index greater than it's size minus 1 because cv::getTrackbarPos() goes all the way to (sceneWithMaxMatches - 1). If the trackbar's position goes out of range for the currently selected vector with matches, I simply set the matchDraw-image in "Matches for current image" to the very last in the vector. Here I exploit the fact that the indexing can't go below zero as well as the trackbar's position so there is not need to check this but only what comes after the initial position 0. If this is not your case make sure you check the lower bound too and not only the upper.
Hope this helps!
I am trying to "visualize" a list of numbers from a .csv file.
I could do that by writing a blender script and thats what I already did.
But I would like to know how the Add Mesh: Extra Object - Math Function could help me (or other functions/addons/anything).
I would like to have a 2D Line (x=+1, y=0, z= value from list) that I would rotate afterwards.
In other words can I convert a list of numbers into a function ?
Sorry if that is a stupid question.
Thanks for the help.
Where The Extra Object - Math Function addon uses minU maxU and stepU as user input values that are used to calculate the value of u before evaluating the function to generate the mesh, you want to let the user input an int value and use it as an index into an array -
AvailZOptions = [1.3, 2.6, 5.2, 10.4]
lineEnd = [xvalue, yvalue, AvailZOptions[OptZUserChoice]]
Another option would be to get the zValue from a function -
def CalcZValue:
if OptZUserChoice = 1:
return 1.3
elif OptZUserChoice = 2:
return 2.6 * cos(x)
lineEnd = [xvalue, yvalue, CalcZValue]
I want to add a sprite2 to sprite1, scale the width of of sprite 1 without scaling sprite2.
I found the code below part of the Cocos2d api; CCSprite.h line 54, but I don't know how to use it nor what the "1<<2" means.
Basically, I'm doing the following but it's not working:
[self addChild: sprite1];
[sprite1 addChild: sprite2]
sprite1.scaleX = 2;
sprite2.CC_HONOR_PARENT_TRANSFORM_SCALE = false;???
Yeah not sure how to use the enum.
thank you
typedef enum {
//! Translate with it's parent
CC_HONOR_PARENT_TRANSFORM_TRANSLATE = 1 << 0,
//! Rotate with it's parent
CC_HONOR_PARENT_TRANSFORM_ROTATE = 1 << 1,
//! Scale with it's parent
CC_HONOR_PARENT_TRANSFORM_SCALE = 1 << 2,
//! All possible transformation enabled. Default value.
CC_HONOR_PARENT_TRANSFORM_ALL = CC_HONOR_PARENT_TRANSFORM_TRANSLATE | CC_HONOR_PARENT_TRANSFORM_ROTATE | CC_HONOR_PARENT_TRANSFORM_SCALE,
} ccHonorParentTransform;
<< - is a bit operation of a shift (my native language is russian and i've translated as is - not sure it's correct). But it is not required for you to understand how it work in this situation because in this case it's just a method to fill the enum values.
From cocos2d documentation
- (ccHonorParentTransform) honorParentTransform [read, write, assign]
whether or not to transform according to its parent transfomrations. Useful for health bars. eg: Don't rotate the health bar, even if the parent rotates. IMPORTANT: Only valid if it is rendered using an CCSpriteBatchNode.
Are you using batch rendering ?
EDIT:
This line is very strange (doesn't it give a warning?)
sprite2.CC_HONOR_PARENT_TRANSFORM_SCALE = false
You should write
sprite2.honorParentTransform &= ~CC_HONOR_PARENT_TRANSFORM_SCALE;
PS: The enum is created using bit operations because it's give you the ability to misc the configuration. For example you can write
sprite2.honorParentTransform &= ~(CC_HONOR_PARENT_TRANSFORM_SCALE | CC_HONOR_PARENT_TRANSFORM_ROTATE);
It will enable both translate and rotate
So the honorParentTransform is a bitmask, that allows you to configure it's configuration - not only use some predefined values but also use there combinations.
Here you can write more about bitwise operations
http://www.cprogramming.com/tutorial/bitwise_operators.html
In our case is happening something like this:
You have a current mask for example 01101111 (it is 32 bit really)
and CC_HONOR_PARENT_TRANSFORM_SCALE is something like this 00001000 - it have only one nonzero bit. ~ - is inversion: so it transform 00010000 to 11101111 and then you make the bitwise addition with you current mask - so all the bits will be preserved except the forth one!