TensorMath
NamespaceNamespace in the Lens Scripting API.
- Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.
Enumerations
| Enumeration | Description |
|---|---|
| BorderType | - |
| ThresholdMethod | - |
Functions
| Function | Description |
|---|---|
| addScalar | Adds a scalar value to each element of inTensor and puts the result into outTensor. |
| addTensors | Adds inTensorA to inTensorB and puts the result into outTensor. See the broadcasting rules for elementwise operations. |
| amplitudeToDb | Converts inTensor from the amplitude scale to the decibel scale. |
| applyBoxFilter | Blurs an image tensor using the box filter. |
| applyNMS | - |
| applyThreshold | Applies a fixed-level threshold to each array element. |
| approximatePolygonalCurve | Approximates a polygonal curve with the specified precision. |
| argMax | Returns the indices of the maximum values along an the channels of inTensor, with the specified inShape. The result is put into outTensor. |
| argSort | Similar to numpy.argsort(), but in TensorMath, we have no kind and order parameters. Also, tensor is always 3D, and axis can be equal to 0(x), 1(y) or 2(z). |
| argSortMasked | Applies a list of indices of a tensor in sorted order of their corresponding values in the tensor to the given outTensor. Only indices whose corresponding values are not equal to 0 in the provided mask will be returned. Indices from the original tensor, before applying the mask, will be returned in the provided array. Returns the size of the list of indices applied to the outTensor (note: this will be equal to the number of non-zero values provided in the mask). eg: var inTensor = [5.0, 2.0, 1.0, 3.0, 7.0, -1.0, -5.0]; var mask = [1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0]; var outTensor = new Uint32Array(7); var order = SortOrder.Ascending; var size = TensorMath.argSortMasked(inTensor, mask, outTensor, order); print(outTensor.subarray(size)); // Expected: [2, 1, 3, 0, 4] |
| clamp | Clamps all values of inTensor between minVal and maxVal, and puts the result into outTensor. |
| concat | Concatenates inTensorA and inTensorB along the specified axis and puts the result to the outTensor. Input arrays have to have same dimension along other 2 axes. |
| dilate | Dilates an image by using a specific structuring element. |
| divTensors | Divides inTensorA by inTensorB and puts the result into outTensor. See broadcasting rules for elementwise operations. |
| drawLine | Draws a line segment connecting two points. |
| erode | Erodes an image by using a specific structuring element. |
| fillConvexPoly | Fills a convex polygon. |
| fillPoly | Fills a polygon. Note that you should pass an Array of Int32Array-s (polygonsTensors). |
| findContours | Returns contours. Note that: contours are sorted from the largest to the smallest; 2) We cannot return Array of TypedArray-s, so all contours data is stored in single outTensor and Array with sizes of each contour is returned. |
| findMinDistancesBetween | Finds minimum distances between each 2D point from one array, to 2D points in another array. |
| getContour | Looks for contour points in a grayscale texture, or any one-channel tensor. |
| getRotatedRectPoints | - |
| getVectorsLength | Calculates the length of all vectors in an array. Vectors can be of any dimension count. |
| isInRectangle | Checks for each 2D point whether it is inside of a rectangle. |
| max | Places the maximum values of inTensor into outTensor. |
| maxDistanceBetweenPoints | From the input points, finds the two points with the maximum distance between them and returns this distance. Works with points of any dimension count. |
| maxInSlideWindow | If we consider the tensor as a 3D array, this function finds the indexes of the maximum element in each subarray of size window. |
| min | Places the minimum values of inTensor into outTensor. |
| minAreaRect | Return TensorMath's format of RotatedRect. |
| minInSlideWindow | If we consider the tensor as a 3D array, this function finds the indexes of the minimum element in each subarray of size window. |
| mulMatToPoints | Multiply a matrix by a set of points through an efficient batch operation. |
| mulScalar | Multiplies each element of inTensor by a scalar value and puts the result into outTensor. |
| mulTensors | Multiplies inTensorA and inTensorB and puts the result into outTensor. See broadcasting rules for elementwise operations. |
| opticalFlow | Stabilizes image objects between two consecutive frames caused by camera or object movement. Results are written to the points array. |
| permute | Rearranges the inTensor of inShape according to the desired ordering and puts the result into outTensor. |
| polarSort2d | Sorts 2D points by polar angle relative to the center point. |
| power | Raises elements of inTensor to the power of val, and puts the results into outTensor. |
| powerToDb | Converts inTensor from the power scale to the decibel scale. |
| projectPoints | Project 3D points into 2D space using an efficient batch operation. |
| repeat | Duplicates inTensor elements and store result in the outTensor. |
| rotatePoints3d | Applies a rotation to each point in a set of 3D points, and places the results in outPoints. |
| smoothPoints | Smooths a polygon formed by input points. Works with points of any dimension count, for example 2 for 2D points or 3 for 3D points. Results are written to outTensor. |
| softArgMax | Applies softArgMax function to the inTensor, with the specified inShape. The result is put into outTensor. |
| softMax | Applies softMax function to inTensor, with the specified inShape. The result is put into outTensor. |
| solvePnP | Estimates the object pose given a set of object points (inObjectPoints), their corresponding image projections (inImagePoints), and the intrinsic camera matrix (transform). |
| solvePnPExtended | Estimates the object pose given a set of object points (inObjectPoints), their corresponding image projections (inImagePoints), and the intrinsic camera matrix (cameraIntrinsicsMatrix). Similar to solvePnP but has additional camera distortion coefficient settings. |
| solvePnPRansac | solvePnPRansac is very similar to solvePnPExtended except that it uses Random Sample Consensus ( RANSAC ) for robustly estimating the pose. |
| subpixelArgMax | Applies subpixelArgMax function to the inTensor, with the specified inShape and kernel size. The result is put into outTensor. |
| subTensors | Subtracts inTensorB from inTensorA and puts the result into outTensor. See the broadcasting rules for elementwise operations. |
| sum | Calculate the sum of the inTensor elements and store result in the outTensor. |
| textureToGrayscale | Converts the texture to a set of 0-255 grayscale values, and outputs the result into outTensor. |