Skip to content

Commit

Permalink
1. add more constructors to ImageLabelView
Browse files Browse the repository at this point in the history
2. update doc
  • Loading branch information
SirLYC committed Mar 30, 2019
1 parent e4831ce commit ecae63a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ captures/

# IntelliJ
*.iml
.idea/
.idea

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
Expand Down
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,71 @@
# ImageLabelView
[![](https://jitpack.io/v/SirLYC/ImageLabelView.svg)](https://jitpack.io/#SirLYC/ImageLabelView)
A view for data-labeling(a tool for machine learning).

![1](https://github.com/SirLYC/ImageLabelView/blob/master/images/1.gif?raw=true)
![2](https://github.com/SirLYC/ImageLabelView/blob/master/images/2.gif?raw=true)

## Install
**Step 1.** Add it in your root build.gradle at the end of repositories:

``` gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
````
**Step 2.** Add the dependency

``` gradle
dependencies {
implementation 'com.github.SirLYC:ImageLabelView:{latest version}'
}
```
## Use
> You can check [sample code](https://github.com/SirLYC/ImageLabelView/tree/master/sample) here
**Step1.** Add to your layout

Just write like this. **No custom attributes** for now.
``` xml
<com.lyc.imagelabel.ImageLabelView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
```

**Step2.** Set an image to the view

Set a bitmap to the ImageLabelView, and it will start to show this phone like a imageView with **center inside mode**. The bitmap can be null, which will let the view clear old labels...
```kotlin
val bitmap: Bitmap? = ... // download or read from disk
label.setBitmap(bitmap);
```

**Step3.** Do your job in different mode

When a nonnull bitmap is present, there are 4 modes to operate a image.
- PREVIEW<br>
This is default mode. Everytime a new bitmap is set to this view, the mode will change to it.
In this mode, you can move or scale the image to the perfect position and size for labelling.
- DRAW<br>
In this mode, you can draw a new label. Take rectangle for example. When your finger touch the screen and move, there will be a rectangle right on the image whose left and top is your start posintion and right and bottom is your end position.
After your finger up, the view will immediately change to SELECT mode.
- UPDATE<br>
In this mode, you can resize or change label's position. Take rectangle for example, you can drag a regtangle' vertext or a egde to resize it, or move the whole of the rectange (when your finger down right in the rectangle).
- SELECT<br>
When click or long press, a rectangle at your finger's position will be selected (if drawing end, the new-created label will be selected automatically.). When a label is selected, you can get it by
``` kotlin
label.selectingLabel()
```
At this time, you may let user to input or do other things to change the message of the label or just delete it.

### Step4: Collect your data
Just get the label and call it's **getData()** or get its **message property**!

## Todo/Fix
- [ ] fix state loss after config changes (such as screen orientation, languages...)
- [ ] circle label
Expand Down
15 changes: 13 additions & 2 deletions imagelabel/src/main/java/com/lyc/imagelabel/ImageLabelView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package com.lyc.imagelabel

import android.annotation.TargetApi
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
Expand All @@ -37,8 +38,18 @@ import androidx.annotation.*
* @date 2019/3/22
* @email kevinliu.sir@qq.com
*/
class ImageLabelView(context: Context, attrs: AttributeSet?) : View(context, attrs), GestureDetector.OnGestureListener,
ScaleGestureDetector.OnScaleGestureListener {
class ImageLabelView : View, GestureDetector.OnGestureListener, ScaleGestureDetector.OnScaleGestureListener {

constructor(context: Context) : super(context)

constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)

constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

@TargetApi(21)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(
context, attrs, defStyleAttr, defStyleRes
)

// the image to be labeled
private var labelBitmap: Bitmap? = null
Expand Down

0 comments on commit ecae63a

Please sign in to comment.