def __init__(self): Plugin.__init__(self) # Appearance self.help = "Extracts the input image size." self.label = "Get Size" self.color = "250:20:30:150" self.in_types = ["mosaicode_c_opencv.extensions.ports.image"] self.out_types = ["mosaicode_c_opencv.extensions.ports.rect"] self.group = "Experimental" self.time_shifts = False # ------------------------------C/OpenCv code-------------------------- self.codes[2] = \ '\nif(block$id$_img_i0)\n{\n' + \ ' \tblock$id$_rect_o0 = cvRect( 0, 0, ' + \ 'block$id$_img_i0->width, block$id$_img_i0->height);\n' + \ '}\n' self.language = "c" self.framework = "opencv"
def __init__(self): Plugin.__init__(self) # Appearance self.help = "Eleva cada ponto de uma " + \ "imagem a um valor fixo de potência." self.label = "Pow" self.color = "230:230:60:150" self.in_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "input_image", "label": "Input Image" }] self.out_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "output_image", "label": "Output Image" }] self.group = "Math Functions" self.properties = [{ "label": "Exponent", "name": "exponent", "value": 1, "type": MOSAICODE_INT, "lower": 1, "upper": 10, "step": 1 }] # -------------------C/OpenCv code------------------------------------ self.codes[2] = \ '\nif(block$id$_img_i0){\n' + \ 'block$id$_img_o0 = cvCloneImage(block$id$_img_i0);\n' + \ 'cvPow(block$id$_img_i0, block$id$_img_o0, $exponent$);\n' + \ '}\n' self.language = "c" self.framework = "opencv"
def paste(self): """ This method paste a block. """ replace = {} self.current_widgets = [] # interact into blocks, add blocks and change their id clipboard = self.main_window.main_control.get_clipboard() for widget in clipboard: if not isinstance(widget, Block): continue plugin = Plugin(widget) plugin.x += 20 plugin.y += 20 plugin.id = -1 if not self.main_window.main_control.add_block(plugin): return replace[widget.id] = plugin self.current_widgets.append(plugin) # interact into connections changing block ids for widget in clipboard: if not isinstance(widget, Connector): continue # if a connector is copied without blocks if widget.source.id not in replace or widget.sink.id \ not in replace: continue print _("continuing...") source = replace[widget.source.id] source_port = widget.source_port sink = replace[widget.sink.id] sink_port = widget.sink_port self.start_connection(source, source_port) self.current_widgets.append(self.curr_connector) self.end_connection(sink, sink_port) self.update_flows()
def __init__(self): Plugin.__init__(self) # Appearance self.help = "Realiza a soma de duas imagens." self.label = "Sum" self.color = "180:10:10:150" self.in_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "first_image", "label": "First Image" }, { "type": "mosaicode_c_opencv.extensions.ports.image", "name": "first_image", "label": "First Image" }] self.out_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "output_image", "label": "Output Image" }] self.group = "Arithmetic and logical operations" self.codes[0] = r""" // And, Xor, Division, subtraction, sum, or, //multiplication need images with the same size void adjust_images_size(IplImage * img1, IplImage * img2, IplImage * img3){ if(img1->width != img2->width || img1->height != img2->height){ int minW,minH; if(img1->width > img2->width) minW = img2->width; else minW = img1->width; if(img1->height > img2->height) minH = img2->height; else minH = img1->height; cvSetImageROI(img2, cvRect( 0, 0, minW, minH )); cvSetImageROI(img1, cvRect( 0, 0, minW, minH )); cvSetImageROI(img3, cvRect( 0, 0, minW, minH )); } } """ self.codes[2] = \ 'if(block$id$_img_i0 && block$id$_img_i1){\n' + \ 'block$id$_img_o0 = cvCloneImage(block$id$_img_i0);\n' + \ 'adjust_images_size(block$id$_img_i0, ' + \ 'block$id$_img_i1, block$id$_img_o0);\n' + \ 'cvAdd(block$id$_img_i0, block$id$_img_i1, ' + \ 'block$id$_img_o0,0);\n' + \ 'cvResetImageROI(block$id$_img_o0);\n' + \ '}\n' self.codes[1] = "IplImage * block$id$_img_i0 = NULL;\n" + \ "IplImage * block$id$_img_i1 = NULL;\n" + \ "IplImage * block$id$_img_o0 = NULL;\n" self.codes[3] = "cvReleaseImage(&block$id$_img_i0);\n" + \ "cvReleaseImage(&block$id$_img_i1);\n" + \ "cvReleaseImage(&block$id$_img_o0);\n" self.language = "c" self.framework = "opencv"
def test_init(self): System() System.add_plugin(Plugin()) self.main_control.init()
def __init__(self): Plugin.__init__(self) self.help = "Operacão de filtragem que implementa o algoritmo " + \ "Canny para detecção de contornos e bordas." + \ "\nPropriedades\nLimiar 1 e Limiar 2: os dois valores" + \ " de limiar são utilizados em conjunto." + \ "O menor valor é utilizado para a realizar a " + \ "conexão de cantos e bordas." + \ "O maior valor é utilizado para encontrar" + \ " segmentos iniciais das bordas mais significativas." self.label = "Canny" self.color = "50:180:80:150" self.in_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "input_image", "label": "Input Image" }, { "type": "mosaicode_c_opencv.extensions.ports.int", "name": "apertureSize", "label": "Aperture Size" }, { "type": "mosaicode_c_opencv.extensions.ports.int", "name": "threshold1", "label": "Threshold 1" }, { "type": "mosaicode_c_opencv.extensions.ports.int", "name": "threshold2", "label": "Threshold 2" }] self.out_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "output_image", "label": "Output Image" }] self.group = "Gradients, Edges and Corners" self.properties = [{ "label": "Aperture Size", "name": "apertureSize", "type": MOSAICODE_INT, "lower": 1, "upper": 10, "value": 3, "step": 1 }, { "label": "Threshold 1", "name": "threshold1", "type": MOSAICODE_INT, "lower": 1, "upper": 100, "value": 16, "step": 1 }, { "label": "Threshold 2", "name": "threshold2", "type": MOSAICODE_INT, "lower": 1, "upper": 100, "value": 33, "step": 1 }] # -------------------------C/OpenCV code---------------------------- self.codes[1] = \ '// $id$ Canny\n' + \ 'IplImage * block$id$_img_i0 = NULL;\n' + \ 'IplImage * block$id$_img_o0 = NULL;\n' + \ 'int block$id$_int_i1 = $prop[apertureSize]$;\n' + \ 'int block$id$_int_i2 = $prop[threshold1]$;\n' + \ 'int block$id$_int_i3 = $prop[threshold2]$;\n' self.codes[2] = \ "if(block$id$_img_i0){ //Canny Code\n" + \ "\tif (block$id$_int_i1 < 1) block$id$_int_i1 = 1;\n" + \ "\tif (block$id$_int_i2 < 1) block$id$_int_i2 = 1;\n" + \ "\tif (block$id$_int_i3 < 1) block$id$_int_i3 = 1;\n" + \ "\tif (block$id$_int_i1 > 10) block$id$_int_i1 = 10;\n" + \ "\tif (block$id$_int_i2 > 100) block$id$_int_i2 = 100;\n" + \ "\tif (block$id$_int_i3 > 100) block$id$_int_i3 = 100;\n" + \ "\tblock$id$_img_o0 = cvCloneImage(block$id$_img_i0);\n" + \ "\tIplImage * tmpImg$id$ =" + \ " cvCreateImage(cvGetSize(block$id$_img_i0),8,1);\n" + \ "\tif(block$id$_img_i0->nChannels == 3){\n" + \ " \t\tcvCvtColor(block$id$_img_i0," + \ " tmpImg$id$ ,CV_RGB2GRAY);\n" + \ "\t}else{\n" + \ " \t\ttmpImg$id$ = block$id$_img_i0 = NULL;\n" + \ "}\n" + \ "cvCanny(tmpImg$id$, tmpImg$id$, block$id$_int_i2," + \ " block$id$_int_i1, block$id$_int_i3);\n" + \ "\tif(block$id$_img_i0->nChannels == 3){\n" + \ " \t\tcvCvtColor(tmpImg$id$, " + \ "block$id$_img_o0,CV_GRAY2RGB);\n" + \ "\t}else{\n" + \ " \t\tcvCopyImage(tmpImg$id$, block$id$_img_o0);\n" + \ "\t}\n" + \ "\tcvReleaseImage(&tmpImg$id$);\n" + \ "} // End Canny Code\n" self.codes[3] = "cvReleaseImage(&block$id$_img_i0);\n" + \ "cvReleaseImage(&block$id$_img_o0);\n" self.language = "c" self.framework = "opencv"
def __init__(self): Plugin.__init__(self) # Appearance self.help = "Operação morfológica que provoca dilatação " + \ "nos objetos de uma imagem, aumentando suas dimensões." self.label = "Dilate" self.color = "180:230:220:150" self.in_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "input_image", "label": "Input Image" }] self.out_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "output_image", "label": "Output Image" }] self.group = "Morphological Operations" self.properties = [{ "label": "Mask Size X", "name": "masksizex", "type": MOSAICODE_COMBO, "values": ["1", "3", "5", "7"], "value": "3" }, { "label": "Mask Size Y", "name": "masksizey", "type": MOSAICODE_COMBO, "values": ["1", "3", "5", "7"], "value": "3" }, { "label": "Iterations", "name": "iterations", "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1, "value": 1 }] # ----------------------------C/OpenCv code--------------------------- self.codes[1] = \ 'IplImage * block$id$_img_i0 = NULL;\n' + \ 'IplImage * block$id$_img_o0 = NULL;\n' + \ 'int block$id$_arg_iterations = $iterations$;\n' + \ 'IplConvKernel * block$id$_arg_mask = ' + \ 'cvCreateStructuringElementEx($masksizex$ , $masksizey$, 1, 1,CV_SHAPE_RECT,NULL);\n' self.codes[2] = ''' if(block$id$_img_i0){ block$id$_img_o0 = cvCloneImage(block$id$_img_i0); cvDilate(block$id$_img_i0, block$id$_img_o0, block$id$_arg_mask, block$id$_arg_iterations); } ''' self.codes[3] = "cvReleaseImage(&block$id$_img_i0);\n" + \ "cvReleaseImage(&block$id$_img_o0);\n" self.language = "c" self.framework = "opencv"
def test_init(self): model = Plugin() model.load(None)
def __init__(self): Plugin.__init__(self) self.maxDist = 60 # Appearance self.help = 'Input1 is the left image and Input2 " + \ "is the right image. Output is the depth image.' self.label = "images/stereoCorr.png" self.color = "10:10:20:150" self.in_types = [ "mosaicode_c_opencv.extensions.ports.image", "mosaicode_c_opencv.extensions.ports.image" ] self.out_types = ["mosaicode_c_opencv.extensions.ports.image"] self.group = "Feature Detection" self.properties = [{ "name": "Max Distance", "label": "maxDist", "type": MOSAICODE_INT, "lower": 0, "upper": 655, "step": 1 }] # -------------------C/OpenCv code------------------------------------ self.codes[1] = \ 'IplImage * block$id$_img_i0 = NULL;\n' + \ 'IplImage * block$id$_img_i1 = NULL;\n' + \ 'IplImage * block$id$_img_o0 = NULL;\n' + \ 'IplImage * block$id$_img_ts0 = NULL;\n' + \ 'IplImage * block$id$_img_ts1 = NULL;\n' self.codes[2] = \ '\nif(block$id$_img_i0 && block$id$_img_i1)\n{\n' + \ ' if(!block$id$_img_o0)\n' + \ ' block$id$_img_o0 = cvCreateImage' + \ '(cvGetSize(block$id$_img_i0), IPL_DEPTH_8U, 1);\n' + \ ' if(!block$id$_img_ts0)\n' + \ ' block$id$_img_ts0 = cvCreateImage' + \ '(cvGetSize(block$id$_img_i0), IPL_DEPTH_8U, 1);\n' + \ ' if(!block$id$_img_ts1)\n' + \ ' block$id$_img_ts1 = cvCreateImage' + \ '(cvGetSize(block$id$_img_i0), IPL_DEPTH_8U, 1);\n' + \ ' cvCvtColor(block$id$_img_i0, ' + \ 'block$id$_img_ts0, CV_BGR2GRAY);\n' + \ ' cvCvtColor(block$id$_img_i1, ' + \ 'block$id$_img_ts1, CV_BGR2GRAY);\n' + \ ' cvFindStereoCorrespondence' + \ '(block$id$_img_ts0, block$id$_img_ts1, ' + \ 'CV_DISPARITY_BIRCHFIELD,' +\ 'block$id$_img_o0, $maxDist$, 15, 3, 6, 8, 15 );\n}\n' self.codes[3] = \ 'cvReleaseImage(&block$id$_img_o0);\n' + \ 'cvReleaseImage(&block$id$_img_i0);\n' + \ 'cvReleaseImage(&block$id$_img_i1);\n' + \ 'if(block$id$_img_ts0)\n\tcvReleaseImage' + \ '(&block$id$_img_ts0);\n' + \ 'if(block$id$_img_ts1)\n\tcvReleaseImage(&block$id$_img_ts1);\n' self.language = "c" self.framework = "opencv"
def __init__(self): Plugin.__init__(self) self.cascade_name = "/usr/share/mosaicode/images/" + \ "haarcascade_frontalface_alt2.xml" self.min_neighbors = 2 # Appearance self.help = 'Haar (face) Detector finds regions on the input ' + \ 'image according to the given haar-classifier. \n' + \ 'First Output is the center of the first detected feature, ' + \ 'second is a rectangle around the first ' + \ 'detected feature and the third is the input image with ' + \ 'the detected features tagged by a red circle.\n' + \ 'The last output is the number of detected faces.' self.label = "Haar Detector" self.color = "50:220:40:150" self.in_types = ["mosaicode_c_opencv.extensions.ports.image"] self.out_types = [ "mosaicode_c_opencv.extensions.ports.point", "mosaicode_c_opencv.extensions.ports.rect", "mosaicode_c_opencv.extensions.ports.image", "mosaicode_c_opencv.extensions.ports.double" ] self.group = "Feature Detection" self.properties = [ { "name": "File Name", "label": "cascade_name", "type": MOSAICODE_SAVE_FILE }, { "name": "Min neighbors", "label": "min_neighbors", "type": MOSAICODE_INT, "lower": 1, "upper": 99, "step": 1 }, ] # ------------------------------C/OpenCv code-------------------------- self.codes[1] = \ 'IplImage * block$id$_img_i0 = NULL;\n' + \ 'CvPoint block$id$_point_o0 = cvPoint(0,0);\n' + \ 'CvRect block$id$_rect_o1 = cvRect( 0, 0, 1, 1);\n' + \ 'IplImage * block$id$_img_o2 = NULL;\n' + \ 'double block$id$_double_o3 = 0.0;\n' + \ 'static CvMemStorage* block$id$_storage = 0;\n' + \ 'static CvHaarClassifierCascade* block$id$_cascade = 0;\n' + \ 'const char* block$id$_cascade_name = "$cascade_name$";\n' self.codes[2] = \ '\nif(block$id$_img_i0){\n' + \ ' double scale = 1.3;\n' + \ ' block$id$_cascade = (CvHaarClassifierCascade*)' + \ 'cvLoad( block$id$_cascade_name, 0, 0, 0 );\n' + \ ' IplImage* gray = cvCreateImage( cvSize' + \ '(block$id$_img_i0->width,block$id$_img_i0->height), 8, 1 );\n' + \ ' IplImage* small_img = cvCreateImage' + \ '( cvSize( cvRound (block$id$_img_i0->width/scale), cvRound ' + \ '(block$id$_img_i0->height/scale)),8, 1 );\n' + \ ' cvCvtColor( block$id$_img_i0, gray, CV_BGR2GRAY );\n' + \ ' cvResize( gray, small_img, CV_INTER_LINEAR );\n' + \ ' cvEqualizeHist( small_img, small_img );\n' + \ ' if(!block$id$_img_o2)\n' + \ ' block$id$_img_o2 = cvCloneImage(block$id$_img_i0);\n' + \ ' cvCopy(block$id$_img_i0,block$id$_img_o2,0);\n' + \ ' block$id$_storage = cvCreateMemStorage(0);\n' + \ ' cvClearMemStorage( block$id$_storage );\n' + \ ' block$id$_rect_o1 = cvRect( 0, 0, 1, 1);\n' + \ ' CvSeq* faces = cvHaarDetectObjects(small_img, ' + \ 'block$id$_cascade, block$id$_storage,' + \ '1.1,$min_neighbors$, 0/*CV_HAAR_DO_CANNY_PRUNING*/,' + \ 'cvSize(30, 30) );\n' + \ ' block$id$_double_o3 = faces->total;\n' + \ ' if(faces)\n' + \ ' {\n' + \ ' int i;\n' + \ ' for( i = 0; i < (faces ? faces->total : 0); i++ )\n' + \ ' {\n' + \ ' CvRect* r = (CvRect*)cvGetSeqElem( faces, i );\n' + \ ' if(r)\n' + \ ' {\n' + \ ' CvPoint center;\n' + \ ' int radius;\n' + \ ' center.x = cvRound((r->x + ' + \ 'r->width*0.5)*scale);\n' + \ ' center.y = cvRound((r->y + ' + \ 'r->height*0.5)*scale);\n' + \ ' radius = cvRound((r->width + ' + \ 'r->height)*0.25*scale);\n' + \ ' cvCircle( block$id$_img_o2, center, ' + \ 'radius, cvScalarAll(0), 3, 8, 0 );\n' + \ ' if(i == 0)\n' + \ ' {\n' + \ ' block$id$_point_o0 = center;\n' + \ ' block$id$_rect_o1.x = (r->x)*scale;\n' + \ ' block$id$_rect_o1.y = (r->y)*scale;\n' + \ ' block$id$_rect_o1.width ' + \ '= (r->width)*scale;\n' + \ ' block$id$_rect_o1.height' + \ ' = (r->height)*scale;\n' + \ ' }\n' + \ ' }\n' + \ ' }\n' + \ ' }\n' + \ ' cvReleaseImage( &gray );\n' + \ ' cvReleaseImage( &small_img );\n' + \ '}\n' self.codes[3] = \ 'cvReleaseImage(&block$id$_img_o2);\n' + \ 'cvReleaseImage(&block$id$_img_i0);\n' + \ 'cvReleaseMemStorage(&block$id$_storage);\n' self.language = "c" self.framework = "opencv"
def __init__(self): Plugin.__init__(self) self.minX = 0 self.maxX = 500 self.minY = 0 self.maxY = 500 self.minVal = 0 self.maxVal = 500 self.minORmax = "min" self.criteria = "pos" # Appearance self.help = "Finds min or max from input image and judges " + \ "it according to a custom criteria." self.label = "Find Min or Max" self.color = "50:50:200:150" self.in_types = ["mosaicode_c_opencv.extensions.ports.image"] self.out_types = ["mosaicode_c_opencv.extensions.ports.double", "mosaicode_c_opencv.extensions.ports.point"] self.group = "Feature Detection" self.properties = [{"name": "Min X", "label": "minX", "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1 }, {"name": "Max X", "label": "maxX", "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1 }, {"name": "Min Y", "label": "minY", "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1 }, {"name": "Max Y", "label": "maxY", "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1 }, {"name": "Min Val", "label": "minVal", "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1 }, {"name": "Max Val", "label": "maxVal", "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1 }, {"name": "Min Or Max", "label": "minORmax", "type": MOSAICODE_COMBO, "values": ["min", "max"] }, {"name": "Criteria", "label": "criteria", "type": MOSAICODE_COMBO, "values": ["pos", "val"] } ]
def __init__(self): Plugin.__init__(self) self.language = "javascript" self.framework = "webaudio" self.help = "ADSR" self.label = "ADSR" self.color = "50:150:250:150" self.in_ports = [{ "type": "mosaicode_javascript_webaudio.extensions.ports.sound", "label": "Sound", "name": "sound" }, { "type": "mosaicode_javascript_webaudio.extensions.ports.float", "label": "Event Play", "name": "play" }] self.out_ports = [{ "type": "mosaicode_javascript_webaudio.extensions.ports.sound", "label": "Sound", "name": "sound" }] self.group = "Sound" self.properties = [{ "name": "a", "label": "Attack", "type": MOSAICODE_FLOAT, "lower": 0, "upper": 10000, "step": 1, "value": 5 }, { "name": "d", "label": "Delay", "type": MOSAICODE_FLOAT, "lower": 0, "upper": 10000, "step": 1, "value": 2 }, { "name": "s", "label": "Sustain", "type": MOSAICODE_FLOAT, "lower": 0, "upper": 10000, "step": 1, "value": 100 }, { "name": "r", "label": "Release", "type": MOSAICODE_FLOAT, "lower": 0, "upper": 10000, "step": 1, "value": 50 }, { "name": "g", "label": "Gain", "type": MOSAICODE_FLOAT, "lower": 0, "upper": 10000, "step": 1, "value": 0.5 }] self.codes[0] = """ Envelope = function(context, a, d, s, r, g) { this.node = context.createGain() this.context = context; this.node.gain.value = 0; this.a = a / 1000.0; this.d = d / 1000.0; this.s = s / 1000.0; this.r = r / 1000.0; this.g = g; } Envelope.prototype.play = function(e) { var time = this.context.currentTime; // Zero this.node.gain.linearRampToValueAtTime(0, time); // Attack time time += this.a; this.node.gain.linearRampToValueAtTime(1, time); // Decay time time += this.d; this.node.gain.linearRampToValueAtTime(0.5, time); // Sustain time (do nothing) time += this.s; // Release time time += this.r; this.node.gain.linearRampToValueAtTime(0, time); } """ self.codes[1] = """
def __init__(self): Plugin.__init__(self) self.masksize = "3x3" self.iterations = 1 # Appearance self.help = "Operação morfológica que provoca erosão " + \ "nos objetos de uma imagem, reduzindo suas dimensões." self.label = "Erosion" self.color = "180:230:220:150" self.in_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "input_image", "label": "Input Image" }, { "type": "mosaicode_c_opencv.extensions.ports.int", "name": "interaction", "label": "Interactions" }] self.out_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "output_image", "label": "Output Image" }] self.group = "Morphological Operations" self.properties = [{ "label": "Mask Size X", "name": "masksizex", "type": MOSAICODE_COMBO, "values": ["1", "3", "5", "7"], "value": "3" }, { "label": "Mask Size Y", "name": "masksizey", "type": MOSAICODE_COMBO, "values": ["1", "3", "5", "7"], "value": "3" }, { "name": "Iterations", "label": "iterations", "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1 }] # --------------------------C/OpenCv code------------------------------ self.codes[1] = \ 'IplImage * block$id$_img_i0 = NULL; // ERODE input\n' + \ 'int block$id$_int_i1 = $prop[iterations]$; // ERODE iterarions\n' + \ 'IplImage * block$id$_img_o0 = NULL; // ERODE output\n' + \ 'IplConvKernel * block$id$_arg_mask = ' + \ 'cvCreateStructuringElementEx($prop[masksizex]$ , $prop[masksizey]$, 1, 1,CV_SHAPE_RECT,NULL);\n' self.codes[2] = \ '\nif(block$id$_img_i0){\n' + \ 'block$id$_img_o0 = cvCloneImage(block$id$_img_i0);\n' + \ 'cvErode(block$id$_img_i0, block$id$_img_o0, ' + \ 'block$id$_arg_mask, block$id$_int_i1);\n' + \ '}\n' self.language = "c" self.framework = "opencv"
def __new(self, widget=None, data=None): PluginEditor(self, Plugin())
def __init__(self): Plugin.__init__(self) self.language = "javascript" self.framework = "webaudio" self.help = "Sound output" self.label = "Oscillator" self.color = "50:150:250:150" self.in_ports = [{ "type": "mosaicode_javascript_webaudio.extensions.ports.sound", "label": "Osc Frequency", "name": "osc_freq" }, { "type": "mosaicode_javascript_webaudio.extensions.ports.float", "label": "Frequency", "name": "freq" }, { "type": "mosaicode_javascript_webaudio.extensions.ports.float", "name": "type", "label": "Type" }] self.out_ports = [{ "type": "mosaicode_javascript_webaudio.extensions.ports.sound", "name": "sound", "label": "Sound" }] self.group = "Sound" self.properties = [{ "name": "freq", "label": "Frequency", "type": MOSAICODE_FLOAT, "lower": 0, "step": 1, "value": 440 }, { "name": "type", "label": "Type", "type": MOSAICODE_COMBO, "values": ["square", "sine", "sawtooth", "triangle"], "value": "sine" }] self.codes[0] = """ // block_$id$ = Oscillator var block_$id$ = context.createOscillator(); var $in_ports[osc_freq]$ = block_$id$.frequency; var $out_ports[sound]$ = null; var $in_ports[freq]$ = function(value){ block_$id$.frequency.value = value; }; var $in_ports[type]$ = function(value){ oscillator = '' if (value < 1) oscillator = 'square'; if (value == 1) oscillator = 'sine'; if (value == 2) oscillator = 'sawtooth'; if (value > 2) oscillator = 'triangle'; block_$id$.type = oscillator; }; """ self.codes[1] = """
def load(cls, file_name): """ This method loads the block from XML file. Returns: * **Types** (:class:`boolean<boolean>`) """ if os.path.exists(file_name) is False: return parser = XMLParser(file_name) if parser.getTag("MosaicodePlugin") is None: return None plugin = Plugin() plugin.type = parser.getTagAttr("MosaicodePlugin", "type") plugin.language = parser.getTagAttr("MosaicodePlugin", "language") plugin.framework = parser.getTagAttr("MosaicodePlugin", "framework") plugin.label = parser.getTagAttr("MosaicodePlugin", "label") plugin.group = parser.getTagAttr("MosaicodePlugin", "group") plugin.color = parser.getTagAttr("MosaicodePlugin", "color") plugin.help = parser.getTagAttr("MosaicodePlugin", "help") plugin.source = parser.getTagAttr("MosaicodePlugin", "source") count = 0 for code in plugin.codes: plugin.codes[count] = parser.getTag("MosaicodePlugin").getTag("code" + str(count)).getText() count = count + 1 props = parser.getTag("MosaicodePlugin").getTag( "properties").getChildTags("property") for prop in props: plugin.properties.append(ast.literal_eval(prop.getAttr("value"))) in_ports = parser.getTag("MosaicodePlugin").getTag( "in_ports").getChildTags("port") for port in in_ports: plugin.in_ports.append(ast.literal_eval(port.getAttr("value"))) out_ports = parser.getTag("MosaicodePlugin").getTag( "out_ports").getChildTags("port") for port in out_ports: plugin.out_ports.append(ast.literal_eval(port.getAttr("value"))) if plugin.type == "mosaicode.model.plugin": return None return plugin
def __init__(self): Plugin.__init__(self) self.help = "Operação de filtragem destinada a suavizar uma imagem." self.label = "Match Template" self.color = "180:180:10:150" self.in_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "first_image", "label": "First Image" }, { "type": "mosaicode_c_opencv.extensions.ports.image", "name": "second_image", "label": "Second Image" }] self.out_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "output_image", "label": "Output Image" }] self.group = "Feature Detection" self.properties = [{ "label": "Scale Factor", "name": "scaleFactor", "type": MOSAICODE_INT, "lower": 0, "upper": 99, "step": 1, "value": 6 }, { "label": "Method", "name": "method", "type": MOSAICODE_COMBO, "value": 'CV_TM_SQDIFF', "values": [ "CV_TM_CCOEFF_NORMED", "CV_TM_CCOEFF", "CV_TM_CCORR_NORMED", "CV_TM_CCORR", "CV_TM_SQDIFF_NORMED", "CV_TM_SQDIFF" ] }] # ------------------------------C/OpenCv code-------------------------- self.codes[1] = \ 'IplImage * block$id$_img_i0 = NULL;\n' + \ 'IplImage * block$id$_img_i1 = NULL;\n' + \ 'IplImage * block$id$_img_t0 = NULL;\n' + \ 'IplImage * block$id$_img_o0 = NULL;\n' self.codes[2] = \ 'if(block$id$_img_i0 && block$id$_img_i1){\n' + \ '\tdouble width$id$ = block$id$_img_i0->width - ' + \ 'block$id$_img_i1->width +1;\n' + \ '\tdouble height$id$ = block$id$_img_i0->height - ' + \ 'block$id$_img_i1->height +1;\n' + \ '\tCvSize size$id$ = cvSize(width$id$,height$id$);\n' + \ '\tblock$id$_img_t0 = cvCreateImage(size$id$,32,1);\n' + \ '\tblock$id$_img_o0 = cvCreateImage(size$id$,8,1);\n' + \ '\tcvMatchTemplate(block$id$_img_i0 , block$id$_img_i1, ' + \ 'block$id$_img_t0, $method$);\n' + \ '\tcvConvertScale(block$id$_img_t0, block$id$_img_o0, pow(10,-($scaleFactor$)),0);\n' + \ '}\n' self.codes[3] = \ 'cvReleaseImage(&block$id$_img_o0);\n' + \ 'cvReleaseImage(&block$id$_img_t0);\n' + \ 'cvReleaseImage(&block$id$_img_i1);\n' + \ 'cvReleaseImage(&block$id$_img_i0);\n' self.language = "c" self.framework = "opencv"
def __init__(self): Plugin.__init__(self) self.language = "c" self.framework = "opencv" self.help = "Adiciona bordas na imagem." self.label = "Add Border" self.color = "0:180:210:150" self.in_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "input_image", "label": "Input Image" }, { "type": "mosaicode_c_opencv.extensions.ports.int", "name": "border_size", "label": "Border Size" }] self.out_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "output_image", "label": "Output Image" }] self.group = "Experimental" self.properties = [{ "label": "Color", "name": "color", "type": MOSAICODE_COLOR, "value": "#FF0000" }, { "name": "type", "label": "Type", "type": MOSAICODE_COMBO, "value": "IPL_BORDER_CONSTANT", "values": [ "IPL_BORDER_CONSTANT", "IPL_BORDER_REPLICATE", "IPL_BORDER_REFLECT", "IPL_BORDER_WRAP" ] }, { "label": "Border Size", "name": "border_size", "type": MOSAICODE_INT, "value": "50" }] self.codes[0] = \ "CvScalar get_scalar_color(const char * rgbColor){\n" + \ " if (strlen(rgbColor) < 13 || rgbColor[0] != '#')\n" + \ " return cvScalar(0,0,0,0);\n" + \ " char r[4], g[4], b[4];\n" + \ " strncpy(r, rgbColor+1, 4);\n" + \ " strncpy(g, rgbColor+5, 4);\n" + \ " strncpy(b, rgbColor+9, 4);\n" + \ "\n" + \ " int ri, gi, bi = 0;\n" + \ " ri = (int)strtol(r, NULL, 16);\n" + \ " gi = (int)strtol(g, NULL, 16);\n" + \ " bi = (int)strtol(b, NULL, 16);\n" + \ "\n" + \ " ri /= 257;\n" + \ " gi /= 257;\n" + \ " bi /= 257;\n" + \ " \n" + \ " return cvScalar(bi, gi, ri, 0);\n" + \ "}\n" self.codes[1] = \ "IplImage * block$id$_img_i0 = NULL;\n" + \ "int block$id$_int_i1 = $prop[border_size]$;\n" + \ "IplImage * block$id$_img_o0 = NULL;\n" self.codes[2] = \ 'if(block$id$_img_i0){\n' + \ '\tCvSize size$id$ = cvSize(block$id$_img_i0->width +' + \ ' block$id$_int_i1 * 2, block$id$_img_i0->height' + \ ' + block$id$_int_i1 * 2);\n' + \ '\tblock$id$_img_o0 = cvCreateImage(size$id$,' + \ ' block$id$_img_i0->depth,block$id$_img_i0->nChannels);\n' + \ '\tCvPoint point$id$ = cvPoint' + \ '(block$id$_int_i1, block$id$_int_i1);\n' + \ '\tCvScalar color = get_scalar_color("$prop[color]$");\n' + \ '\tcvCopyMakeBorder(block$id$_img_i0, block$id$_img_o0,' + \ ' point$id$, $prop[type]$, color);\n' + \ '}\n'
def setUp(self): """Do the test basic setup.""" plugin = Plugin() self.block_model = BlockModel(plugin)
def test_init(self): model = Plugin()
def __init__(self): Plugin.__init__(self) self.x0 = 0 self.y0 = 0 self.width = 640 self.height = 480 # Appearance self.help = "Corta a Imagem de acordo com o Retangulo de entrada." self.label = "Crop Image" self.color = "50:50:200:150" self.in_types = ["mosaicode_c_opencv.extensions.ports.image", "mosaicode_c_opencv.extensions.ports.rect"] self.out_types = ["mosaicode_c_opencv.extensions.ports.image"] self.group = "Experimental" self.properties = [{"name": "X", "label": "x0", "type": MOSAICODE_INT, "lower": 1, "upper": 65535, "step": 1 }, {"name": "Y", "label": "y0", "type": MOSAICODE_INT, "lower": 1, "upper": 65535, "step": 1 }, {"name": "Width", "label": "width", "type": MOSAICODE_INT, "lower": 1, "upper": 65535, "step": 1 }, {"name": "Height", "label": "height", "type": MOSAICODE_INT, "lower": 1, "upper": 65535, "step": 1 } ] # ------------------------C/OpenCv code-------------------------------- self.codes[1] = \ 'IplImage * block$id$_img_i0 = NULL;\n' + \ 'IplImage * block$id$_img_o0 = NULL;\n' + \ 'CvRect block$id$_rect_i1 = cvRect' + \ '($x0$, $y0$, $width$, $height$);\n' self.codes[2] = \ '\nif(block$id$_img_i0){\n' + \ ' block$id$_rect_i1.x = MAX' + \ '(0,block$id$_rect_i1.x);//Check whether point is negative\n' + \ ' block$id$_rect_i1.y = MAX' + \ '(0,block$id$_rect_i1.y);\n' + \ ' block$id$_rect_i1.x = MIN(block$id$_img_i0->width-1,' + \ 'block$id$_rect_i1.x);//Check whether ' + \ 'point is out of the image\n' + \ ' block$id$_rect_i1.y = MIN' + \ '(block$id$_img_i0->height-1,' + \ 'block$id$_rect_i1.y);\n' + \ ' block$id$_rect_i1.width = MIN' + \ '(block$id$_img_i0->width-block$id$_rect_i1.x,' + \ 'block$id$_rect_i1.width);' + \ '//Check whether rect reaches out of the image\n' + \ ' block$id$_rect_i1.height = MIN(block$id$_img_i0->' + \ 'height-block$id$_rect_i1.y,block$id$_rect_i1.height);\n' + \ ' block$id$_img_o0 = cvCreateImage' + \ '(cvSize(block$id$_rect_i1.width,' + \ 'block$id$_rect_i1.height),' + \ ' block$id$_img_i0->depth,block$id$_img_i0->nChannels);\n' + \ ' cvSetImageROI(block$id$_img_i0,block$id$_rect_i1);\n' + \ ' cvCopyImage(block$id$_img_i0,block$id$_img_o0);\n' + \ '}\n' self.language = "c" self.framework = "opencv"
def __init__(self): Plugin.__init__(self) self.isCenter = True self.isScalling = True self.isFilling = True self.angle = 0 # Appearance self.help = "Adiciona bordas na imagem." self.label = "Rotate Image" self.color = "90:5:10:150" self.in_types = [ "mosaicode_c_opencv.extensions.ports.image", "mosaicode_c_opencv.extensions.ports.double" ] self.out_types = ["mosaicode_c_opencv.extensions.ports.image"] self.group = "Experimental" self.properties = [{ "name": "Use Image Center", "label": "isCenter", "type": MOSAICODE_CHECK }, { "name": "Resize Image To Fit In", "label": "isScalling", "type": MOSAICODE_CHECK }, { "name": "Fill Leftovers", "label": "isFilling", "type": MOSAICODE_CHECK }, { "name": "Point X", "label": "x", "type": MOSAICODE_INT, "value": 20, "lower": 0, "upper": 65535, "step": 1 }, { "name": "Point Y", "label": "y", "value": 20, "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1 }, { "name": "Angle", "label": "angle", "type": MOSAICODE_FLOAT, "lower": 0, "upper": 360, "step": 1 }] # -------------------C/OpenCv code------------------------------------ self.codes[1] = \ 'IplImage * block$id$_img_i0 = NULL;\n' + \ 'double block$id$_double_i1 = $angle$;\n' + \ 'IplImage * block$id$_img_o0 = NULL;\n' self.codes[0] = \ "#define PI 3.1415926535898\n" + \ "double rads(double degs){\n" + \ " return (PI/180 * degs);\n" + \ "}\n\n"
def __init__(self): Plugin.__init__(self) self.masksize = "7x7" # Appearance self.help = "Operação de morfologia matemática para realizar o " + \ "fechamento da imagem de acordo com o elemento estruturante." + \ "Equivale a aplicação de uma dilatação seguida de uma erosão." self.label = "Closing" self.color = "180:230:220:150" self.group = "Morphological Operations" self.in_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "input_image", "label": "Input Image" }, { "type": "mosaicode_c_opencv.extensions.ports.int", "name": "masksizex", "label": "Mask Size X" }, { "type": "mosaicode_c_opencv.extensions.ports.int", "name": "masksizey", "label": "Mask Size Y" }] self.out_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "output_image", "label": "Output Image" }] self.properties = [{ "label": "Mask Size X", "name": "masksizex", "type": MOSAICODE_COMBO, "values": ["1", "3", "5", "7"], "value": "3" }, { "label": "Mask Size Y", "name": "masksizey", "type": MOSAICODE_COMBO, "values": ["1", "3", "5", "7"], "value": "3" }] # -------------------C/OpenCv code--------------------------------- self.codes[1] = \ 'IplImage * block$id$_img_i0 = NULL;\n' + \ 'int block$id$_int_i1 = $masksizex$;\n' + \ 'int block$id$_int_i2 = $masksizey$;\n' + \ 'IplImage * block$id$_img_o0 = NULL;\n' + \ 'IplConvKernel * block$id$_arg_mask = NULL;\n' self.codes[2] = \ '\nif(block$id$_img_i0){\n' + \ 'if (block$id$_int_i1 % 2 == 0) block$id$_int_i1++;\n' + \ 'if (block$id$_int_i2 % 2 == 0) block$id$_int_i2++;\n' + \ 'block$id$_arg_mask = ' + \ 'cvCreateStructuringElementEx(block$id$_int_i1 ,' + \ 'block$id$_int_i2, 1, 1,CV_SHAPE_RECT,NULL);\n' + \ 'IplImage * block$id$_auxImg;\n' + \ 'block$id$_img_o0 = cvCloneImage(block$id$_img_i0);\n' + \ 'block$id$_auxImg = cvCloneImage(block$id$_img_i0);\n' + \ 'cvMorphologyEx(block$id$_img_i0, block$id$_img_o0, NULL,' + \ 'block$id$_arg_mask, CV_MOP_CLOSE, 1);\n}\n' self.codes[3] = \ 'cvReleaseImage(&block$id$_img_o0);\n' + \ 'cvReleaseStructuringElement(&block$id$_arg_mask);\n' + \ 'cvReleaseImage(&block$id$_img_i0);\n' # -------------------------------------------------------------------------- self.language = "c" self.framework = "opencv"
def __init__(self): Plugin.__init__(self) # Appearance self.help = "Permite a operação lógica 'E' entre as duas entradas." + \ " Para esse bloco há duas possibilidades." + \ "Primeira: Executa a operação entre" + \ " duas imagens ponto a ponto." + \ "Segunda: Executa a operação entre um " + \ "valor constante e cada ponto da imagem." self.label = "And" self.color = "10:180:10:150" self.in_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "first_image", "label": "First Image" }, { "type": "mosaicode_c_opencv.extensions.ports.image", "name": "second_image", "label": "Second Image" }] self.out_ports = [{ "type": "mosaicode_c_opencv.extensions.ports.image", "name": "output_image", "label": "Output Image" }] self.group = "Arithmetic and logical operations" self.codes[0] = r""" // And, Xor, Division, subtraction, sum, or, //multiplication need images with the same size void adjust_images_size(IplImage * img1, IplImage * img2, IplImage * img3){ if(img1->width != img2->width || img1->height != img2->height){ int minW,minH; if(img1->width > img2->width) minW = img2->width; else minW = img1->width; if(img1->height > img2->height) minH = img2->height; else minH = img1->height; cvSetImageROI(img2, cvRect( 0, 0, minW, minH )); cvSetImageROI(img1, cvRect( 0, 0, minW, minH )); cvSetImageROI(img3, cvRect( 0, 0, minW, minH )); } } """ self.codes[1] = "// $id$ - And\n" + \ "IplImage * block$id$_img_i0 = NULL;\n" + \ "IplImage * block$id$_img_i1 = NULL;\n" + \ "IplImage * block$id$_img_o0 = NULL;\n" self.codes[2] = \ '\nif(block$id$_img_i0 && block$id$_img_i1){\n' + \ '\tblock$id$_img_o0 = cvCloneImage(block$id$_img_i0);\n' + \ '\tadjust_images_size(block$id$_img_i0, ' + \ 'block$id$_img_i1, block$id$_img_o0);\n' + \ '\tcvAnd(block$id$_img_i0, ' + \ 'block$id$_img_i1, block$id$_img_o0,0);\n' + \ '\tcvResetImageROI(block$id$_img_o0);\n' + \ '}\n' self.codes[3] = "cvReleaseImage(&block$id$_img_i0);\n" + \ "cvReleaseImage(&block$id$_img_i1);\n" + \ "cvReleaseImage(&block$id$_img_o0);\n" self.language = "c" self.framework = "opencv"
def __init__(self, port_manager, port): self.port_manager = port_manager Gtk.Dialog.__init__(self, _("Port Editor"), self.port_manager, 0, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK)) self.main_control = self self.set_default_size(600, 300) vbox = Gtk.VBox() box = self.get_content_area() box.pack_start(vbox, True, True, 0) self.type = StringField({"label": _("Type")}, None) self.language = StringField({"label": _("Language")}, None) self.label = StringField({"label": _("Label")}, None) self.color = ColorField({"label": _("Color")}, None) self.color.set_parent_window(self) self.code = CodeField({"label": _("Code")}, None) self.multiple = CheckField({"label": _("Multiple")}, None) self.input_code_widgets = [] self.output_code_widgets = [] for code in Plugin().codes: self.input_code_widgets.append(CodeField({"label": ""}, None)) self.output_code_widgets.append(CodeField({"label": ""}, None)) if port is not None: System() self.type.set_value(port) self.language.set_value(System.ports[port].language) self.label.set_value(System.ports[port].label) self.color.set_value(System.ports[port].color) self.code.set_value(System.ports[port].code) self.multiple.set_value(System.ports[port].multiple) count = 0 for code in Plugin().codes: self.input_code_widgets[count].set_value( System.ports[port].input_codes[count]) self.output_code_widgets[count].set_value( System.ports[port].output_codes[count]) count = count + 1 vbox.pack_start(self.type, False, False, 1) vbox.pack_start(self.language, False, False, 1) vbox.pack_start(self.label, False, False, 1) vbox.pack_start(self.color, False, False, 1) vbox.pack_start(self.multiple, False, False, 1) self.code_notebook = Gtk.Notebook() self.code_notebook.set_scrollable(True) vbox.pack_start(self.code_notebook, True, True, 1) self.code_notebook.append_page(self.code, Gtk.Label(_("Connection Code"))) count = 0 for code_widget in self.input_code_widgets: self.code_notebook.append_page(code_widget, Gtk.Label(_("Input Code " + \ str(count)))) count = count + 1 count = 0 for code_widget in self.output_code_widgets: self.code_notebook.append_page(code_widget, Gtk.Label(_("Output Code " + \ str(count)))) count = count + 1 self.show_all() result = self.run() if result == Gtk.ResponseType.OK: self.__save() self.close() self.destroy()