Skip to content
Permalink
Browse files

multiple bounding boxes working including focus current

  • Loading branch information...
danlester committed May 22, 2019
1 parent 2c05812 commit df88d92c8bf90fa4e9f4d9f2152674c89ddc7814
@@ -30,7 +30,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f5840bbeb22c4170b6343f77971b73e0",
"model_id": "3f6f4ab528de41c28caac5acd1b43a2c",
"version_major": 2,
"version_minor": 0
},
@@ -67,6 +67,56 @@
"display(i)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[[1],\n",
" [0],\n",
" [1]],\n",
"\n",
" [[0],\n",
" [0],\n",
" [0]],\n",
"\n",
" [[2],\n",
" [2],\n",
" [0]],\n",
"\n",
" [[0],\n",
" [0],\n",
" [0]],\n",
"\n",
" [[0],\n",
" [0],\n",
" [0]],\n",
"\n",
" [[0],\n",
" [0],\n",
" [0]],\n",
"\n",
" [[0],\n",
" [0],\n",
" [0]],\n",
"\n",
" [[0],\n",
" [0],\n",
" [0]]])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"targets_cl"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -76,13 +126,13 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7221dc40a3bf450cad9fe15a33311d29",
"model_id": "69eaa52423be40efb52b97dd2990e4cf",
"version_major": 2,
"version_minor": 0
},
@@ -154,14 +204,14 @@
{
"data": {
"text/plain": [
"([0, 0, 0, 0, 0, 0, 0, 0], array([[0, 0, 0, 0],\n",
" [0, 0, 0, 0],\n",
" [0, 0, 0, 0],\n",
" [0, 0, 0, 0],\n",
" [0, 0, 0, 0],\n",
" [0, 0, 0, 0],\n",
" [0, 0, 0, 0],\n",
" [0, 0, 0, 0]]))"
"([0, 0, 0, 0, 0, 0, 0, 0], array([[139, 56, 154, 132],\n",
" [110, 144, 190, 99],\n",
" [168, 58, 82, 90],\n",
" [179, 103, 91, 86],\n",
" [ 0, 0, 0, 0],\n",
" [ 0, 0, 0, 0],\n",
" [ 0, 0, 0, 0],\n",
" [ 0, 0, 0, 0]]))"
]
},
"execution_count": 4,
@@ -0,0 +1,29 @@
var widgets = require('@jupyter-widgets/base');
var controls = require('@jupyter-widgets/controls');

require("./style.css");

var _ = require('lodash');

var $ = require('jquery');


var FocusTextView = widgets.TextView.extend({

events: function () {
console.log("EVENTS !!!");
var d = FocusTextView.__super__.events(this, arguments);
d['click input'] = 'handleFocus';
return d;
}

});

FocusTextView.prototype.handleFocus = function(e) {
this.send({ event: 'click' });
};

module.exports = {
FocusTextView: FocusTextView
};

@@ -11,4 +11,5 @@ var _ = require('lodash');

module.exports = require('./innotaterwidget.js');
_.extend( module.exports, require('./imagewidget.js') );
_.extend( module.exports, require('./customwidgets.js') );
module.exports['version'] = require('../package.json').version;
@@ -277,7 +277,7 @@ var InnotaterImagePadView = widgets.DOMWidgetView.extend({
ctx.globalAlpha = 0.9;

ctx.beginPath();
ctx.strokeStyle = "#FFFFFF";
ctx.strokeStyle = isdrawing ? "#008000" : "#FFFFFF";
ctx.rect(x*this.zoom, y*this.zoom, w*this.zoom, h*this.zoom);
ctx.stroke();

@@ -23,6 +23,10 @@ canvas.jupyter-innotater-imagepad.is_bb_source {
opacity: 1.0; /* Disabled TextInnotations still want to be highly readable */
}

.innotater-base .bounding-box-active {
border: green 1px solid;
}

/* Kaggle Overrides */

.innotater-kaggle .widget-hbox {
@@ -0,0 +1,50 @@
import ipywidgets as widgets
from ipywidgets.widgets import CallbackDispatcher
from traitlets import Unicode


@widgets.register
class FocusText(widgets.Text):
_view_name = Unicode('FocusTextView').tag(sync=True)
#_model_name = Unicode('FocusTextModel').tag(sync=True)
_view_module = Unicode('jupyter-innotater').tag(sync=True)
#_model_module = Unicode('jupyter-innotater').tag(sync=True)
_view_module_version = Unicode('~0.1.0').tag(sync=True)
#_model_module_version = Unicode('~0.1.0').tag(sync=True)

def __init__(self, **kwargs):
super(FocusText, self).__init__(**kwargs)
self._click_handlers = CallbackDispatcher()
self.on_msg(self._handle_focustext_msg)

def on_click(self, callback, remove=False):
"""Register a callback to execute when the button is clicked.
The callback will be called with one argument, the clicked button
widget instance.
Parameters
----------
remove: bool (optional)
Set to true to remove the callback from the list of callbacks.
"""
self._click_handlers.register_callback(callback, remove=remove)

def click(self):
"""Programmatically trigger a click event.
This will call the callbacks registered to the clicked button
widget instance.
"""
self._click_handlers(self)

def _handle_focustext_msg(self, _, content, buffers):
"""Handle a msg from the front-end.
Parameters
----------
content: dict
Content of the msg.
"""
if content.get('event', '') == 'click':
self.click()
@@ -1,5 +1,6 @@
from .imagewidget import ImagePad
from ipywidgets import Checkbox, Select, Text, Textarea, Dropdown
from .customwidgets import FocusText
from ipywidgets import Checkbox, Select, Textarea, Dropdown
import re
from pathlib import Path

@@ -176,9 +177,11 @@ def post_widget_create(self, datamanager):
if self.sourcedw is not None:
self.sourcedw.register_bbox_watcher(self.repeat_index)
self.sourcedw.widget_observe(self.rectChanged, names='rects')
self.sourcedw.widget_observe(self.rectIndexChanged, names='rect_index')
self.get_widget().on_click(self.widget_clicked)

def _create_widget(self):
return Text(layout=self.layout, disabled=self.disabled)
return FocusText(layout=self.layout, disabled=self.disabled)

def update_ui(self, uindex):
self.get_widget().value = self._value_to_str(self._get_data(uindex))
@@ -213,6 +216,17 @@ def rectChanged(self, change):
v = self._value_to_str(r[ri*4:ri*4+4])
self.get_widget().value = v

def rectIndexChanged(self, change):
if self.sourcedw is not None:
if self.sourcedw.get_widget().rect_index == self.repeat_index:
self.get_widget().add_class('bounding-box-active')
else:
self.get_widget().remove_class('bounding-box-active')

def widget_clicked(self, w):
if self.sourcedw is not None:
self.sourcedw.get_widget().rect_index = self.repeat_index


class MultiClassInnotation(Innotation):

@@ -25,12 +25,17 @@ def setRect(self, repeat_index, x,y,w,h):
if repeat_index == -1:
repeat_index = 0

while len(self.rects) < (repeat_index+1)*4:
self.rects.extend([0,0,0,0])
self.rects[repeat_index*4] = int(x)
self.rects[repeat_index*4+1] = int(y)
self.rects[repeat_index*4+2] = int(w)
self.rects[repeat_index*4+3] = int(h)
r = [int(a) for a in self.rects]

while len(r) < (repeat_index+1)*4:
r.extend([0,0,0,0])

r[repeat_index*4] = int(x)
r[repeat_index*4+1] = int(y)
r[repeat_index*4+2] = int(w)
r[repeat_index*4+3] = int(h)

self.rects = r

def set_max_repeats(self, max_repeats):
self.max_repeats = max_repeats

0 comments on commit df88d92

Please sign in to comment.
You can’t perform that action at this time.