LATEST VERSION 1.61 (21.11.2016)

Description

This module utilise OpenCV library and provide simple image processing operations. This module can be easy expanded with new functions.

uimagetool pion

Module functions

UImageTool.loadImage("filename"); - get image from file,
UImageTool.loadImage2Buffer("filename"); - load image from file to internal buffer,
UImageTool.setImage(image); - copy image from source
UImageTool.putImage("filename", x, y, scale, opacity); - load image from file
  "filename" - filename or left empty ("") to get image from buffer (use loadImage2Buffer(..) function first),
  x, y - location,
  scale - resize image if not 1 (float and must be >0),
  opacity - 0..1.
UImageTool.saveImage("filename"); - save image to file,
UImageTool.setImage(image); - copy image from source
UImageTool.createImage(width, height, red, green, blue); - create image filled given color,
UImageTool.getChannel(channel); - get image from only one channel ex. in RGB: 0 - red, 1 - green, 2 - blue,
UImageTool.imgConvert(type); - convert to color space,
type:
  CV_BGR2RGB = 4,
  CV_RGB2BGR = CV_BGR2RGB,
  CV_BGR2GRAY = 6,
  CV_RGB2GRAY = 7,
  CV_GRAY2BGR = 8,
  CV_GRAY2RGB = CV_GRAY2BGR,
  CV_BGR2HSV = 40,
  CV_RGB2HSV = 41,
  CV_HSV2BGR = 54,
  CV_HSV2RGB = 55,
  more conversions in OpenCV docu.
UImageTool.imgResize(scale); - resize image with given scale (float) scale>0,
UImageTool.imgROI(x,y,width,hight); - crop image,
UImageTool.imgRotate(x,y,angle); - rotate image around the point, angle in degree,
UImageTool.imgRotateFlip(operation); - rotate or flip image,
operation:
  ROTATE 90 = 0,
  ROTATE 180 = 1,
  ROTATE 270 = 2,
  FLIP HORIZONTAL = 3,
  FLIP VERTICAL = 4, 
UImageTool.getPixelValue(x,y); - get pixel value,
UImageTool.imgMorphology(operation, shape, size); - morphology operations,
operation:
 CV_MOP_ERODE = 0,
  CV_MOP_DILATE = 1,
  CV_MOP_OPEN = 2,
  CV_MOP_CLOSE = 3,
  CV_MOP_GRADIENT = 4,
  CV_MOP_TOPHAT = 5,
shape:
  MORPH_RECT = 0,
  MORPH_CROSS = 1,
  MORPH_ELLIPSE = 2
UImageTool.imgBlur(size); - blur operation,
UImageTool.imgMedianBlur(size); - median blur operation,
UImageTool.imgThreshold(thresh, thresholdType); - threshold process,
thresholdType:
  THRESH_BINARY = 0, value = value > thresh ? 255 : 0,
  THRESH_BINARY_INV = 1, value = value > thresh ? 0 : 255 ,
  THRESH_TRUNC = 2, value = value > thresh ? thresh : value,
  THRESH_TOZERO = 3, value = value > thresh ? value : 0,
  THRESH_TOZERO_INV = 4, value = value > thresh ? 0 : value
UImageTool.putLine(x1, y1, x2, y2, red, green, blue, thicknes); - put line on image,
UImageTool.putRectangle(x1, y1, x2, y2, red, green, blue, thickness); - put rectangle on image,
UImageTool.putCircle(x, y, radius, red, green, blue, thickness); - put circle on image,
UImageTool.putString("text", x, y, font , fontscale ,red, green, blue, thickness); - put text on image,
UImageTool.time; - last processing time,
UImageTool.width; - image width,
UImageTool.height; - image height,
UImageTool.bufferWidth; - image in buffer width,
UImageTool.bufferHeight; - image in buffer height,
UImageTool.updateImage(); - update image to uimage var,
UImageTool.autoUpdate; - if true always copy processed image to UImage,
UImageTool.image; - UImage variable.

How to use in urbiscript

Example 1

loadModule("UImageTool");
var Global.Tool=UImageTool.new();
Tool.autoUpdate=true;
Tool.createImage(640,480,0,0,0);
Tool.putLine(10, 10, 300, 200, 255, 0, 0, 1);
Tool.putLine(10, 400, 300, 200, 0, 255, 0, 5);
Tool.putCircle(300, 200, 50, 0, 0, 255, 3);
Tool.putCircle(400, 200, 50, 0, 0, 255, -1);
Tool.putRectangle(500, 200, 540, 240, 180, 180, 180, -1);
Tool.putString("My text", 230, 350, 1 , 2, 255, 0, 255, 2);

Example 2

loadModule("UCamera");
var Global.Cam=UCamera.new(0);
loadModule("UImageTool");
var Global.Tool=UImageTool.new();
t: loop {
  Global.Cam.GetImage();
  Tool.setImage(Camera.image);
  Tool.imgMedianBlur(11);
  var pixelVal = Tool.getPixelValue(100, 100);
  Tool.putCircle(100, 100, 40, pixelVal[0], pixelVal[1], pixelVal[2], -1);
  Tool.updateImage;
},

Example 3

// Animation example
 
loadModule("UImageTool");
var Global.Tool=UImageTool.new();
Tool.autoUpdate=true;
Tool.loadImage2Buffer("image.png");
 
var step = 0.01;
t:loop{
  Tool.createImage(640, 480, 200, 200, 200);
  Tool.putImage("", 100*step, 100, 1*step, 1*step);
  step = step + 0.01;
  if (step>=1) step = 0.01;
  sleep(20ms);
},

Download

LINK

 

 

 

EMYS and FLASH are Open Source and distributed according to the GPL v2.0 © Rev. 0.8.0, 27.04.2016

FLASH Documentation