Hi I have integrated the api in android app,but data is not being recognised accurately, recognised data is completely out of the data been passed, I have provided the snippets below how I am storing the points and passing it can you please check it let me know if I am passing the coordinates correctly or any mistake is being done because there's sample for rest api integration in web but here I am trying to do with the android app may be the touch event I am passing may be not the correct way of passing it, thanks.
//Function in the calling class where I am making the api call and the //below snippet I am creating the request body
private fun recognized(): CloudRecoRequestModel {
// val stroke: Stroke = Stroke(sltw.getXpointsList(), sltw.getYpointsList(),sltw.getTime())
val strokeGroup = StrokeGroup(null, sltw.getStroke())
return CloudRecoRequestModel("Math", "DIGITAL_EDIT", listOf(strokeGroup), 96, 96)
}
//custom view to implement the free hand drawing
class DrawingView(private var c: Context,attributes: AttributeSet) : View(c,attributes) {
private var mPaint: Paint
private var xPointsList:ArrayList<Int> =ArrayList()
private var yPointsList:ArrayList<Int> = ArrayList()
private var currentTime:ArrayList<Long> = ArrayList()
private var strokeList:ArrayList<Stroke> = ArrayList()
private var mBitmap: Bitmap? = null
private var mCanvas: Canvas? = null
private val mPath: Path
private val mBitmapPaint: Paint
private val circlePaint: Paint
private val circlePath: Path
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)
mCanvas = Canvas(mBitmap)
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
canvas.drawBitmap(mBitmap, 0f, 0f, mBitmapPaint)
canvas.drawPath(mPath, mPaint)
}
private var mX = 0f
private var mY = 0f
private fun touch_start(x: Float, y: Float) {
mPath.reset()
mPath.moveTo(x, y)
mX = x
mY = y
}
private fun touch_move(x: Float, y: Float) {
val dx = Math.abs(x - mX)
val dy = Math.abs(y - mY)
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2)
mX = x
mY = y
circlePath.reset()
circlePath.addCircle(mX, mY, 30f, Path.Direction.CW)
}
}
private fun touch_up() {
mPath.lineTo(mX, mY)
circlePath.reset()
// commit the path to our offscreen
mCanvas?.drawPath(mPath, mPaint)
// kill this so we don't double draw
mPath.reset()
}
override fun onTouchEvent(event: MotionEvent): Boolean {
val x = event.x
val y = event.y
when (event.action) {
MotionEvent.ACTION_DOWN -> {
xPointsList.add(x.toInt())
yPointsList.add(y.toInt())
currentTime.add(System.currentTimeMillis())
touch_start(x, y)
// strokeList.add(Stroke(xPointsList,yPointsList))
// strokeList.add(Stroke(xPointsList,yPointsList))
invalidate()
}
MotionEvent.ACTION_MOVE -> {
xPointsList.add(x.toInt())
yPointsList.add(y.toInt())
currentTime.add(System.currentTimeMillis())
touch_move(x, y)
// strokeList.add(Stroke(xPointsList,yPointsList))
invalidate()
}
MotionEvent.ACTION_UP -> {
xPointsList.add(x.toInt())
yPointsList.add(y.toInt())
currentTime.add(System.currentTimeMillis())
strokeList.add(Stroke(xPointsList,yPointsList,currentTime))
touch_up()
invalidate()
}
}
return true
}
companion object {
private const val TOUCH_TOLERANCE = 4f
}
init {
mPath = Path()
mBitmapPaint = Paint(Paint.DITHER_FLAG)
circlePaint = Paint()
circlePath = Path()
circlePaint.setAntiAlias(true)
circlePaint.setColor(Color.BLUE)
circlePaint.setStyle(Paint.Style.STROKE)
circlePaint.setStrokeJoin(Paint.Join.MITER)
circlePaint.setStrokeWidth(4f)
this.mPaint = Paint()
mPaint.setAntiAlias(true)
mPaint.setDither(true)
mPaint.setColor(Color.GREEN)
mPaint.setStyle(Paint.Style.STROKE)
mPaint.setStrokeJoin(Join.ROUND)
mPaint.setStrokeCap(Cap.ROUND)
mPaint.setStrokeWidth(2f)
}
fun getXpointsList():ArrayList<Int>{
return xPointsList
}
fun getYpointsList():ArrayList<Int>{
return yPointsList
}
fun getStroke():ArrayList<Stroke>{
return strokeList
}
fun getTime():ArrayList<Long>{
return currentTime
}
}
Thanks
Best Answer
O
Olivier @MyScript
said
almost 3 years ago
Dear Yahya,
thank you for the ink. You indeed have an issue in your algorithm, as if referring to your above request, you will see your request contains 4 times the same stroke.
And your stroke has not been properly split:
Please modify your algorithm to properly split the strokes.
And please find the image of the input given and the output provided.
Thanks and regards
O
Olivier @MyScript
said
almost 3 years ago
Answer
Dear Yahya,
thank you for the ink. You indeed have an issue in your algorithm, as if referring to your above request, you will see your request contains 4 times the same stroke.
And your stroke has not been properly split:
Please modify your algorithm to properly split the strokes.
yahya basique
Hi I have integrated the api in android app,but data is not being recognised accurately, recognised data is completely out of the data been passed, I have provided the snippets below how I am storing the points and passing it can you please check it let me know if I am passing the coordinates correctly or any mistake is being done because there's sample for rest api integration in web but here I am trying to do with the android app may be the touch event I am passing may be not the correct way of passing it, thanks.
Thanks
Dear Yahya,
thank you for the ink. You indeed have an issue in your algorithm, as if referring to your above request, you will see your request contains 4 times the same stroke.
And your stroke has not been properly split:
Please modify your algorithm to properly split the strokes.
Best regards,
Olivier
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstOlivier @MyScript
Dear Yahya,
can you please provide us the full REST request that is posted on our server?
This will allow us to see the ink that is posted, and may help investigating.
Best regards,
Olivier
yahya basique
Thanks for the reply, I just want to make you aware that I did send the timestamp with the coordinates as well, thanks.
And please find the image of the input given and the output provided.
Thanks and regards
Olivier @MyScript
Dear Yahya,
thank you for the ink. You indeed have an issue in your algorithm, as if referring to your above request, you will see your request contains 4 times the same stroke.
And your stroke has not been properly split:
Please modify your algorithm to properly split the strokes.
Best regards,
Olivier