iink SDK Web

Answered

Rest api reco not accurate.

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

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


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

Thanks for the reply, I just want to make you aware that I did send the timestamp with the coordinates as well, thanks.


 

{"contentType":"Math","conversionState":"DIGITAL_EDIT","strokeGroups":[{"strokes":[{"x":[547,547,547,547,547,547,547,547,547,554,575,617,655,676,696,712,721,729,727,629,632,637,641,645,649,649,649,653,653,653,657,657,657,657,657,657,661,661,661,661,661,661,661,762,767,777,790,807,824,854,881,904,933,947,960,968,972,972,972,1035,1035,1039,1043,1047,1050,1050,1054,1058,1062,1062,1062,1062,1062,1066,1066,1066,1066,1066,1066,1066,1066,1066,1066,1066,1070,1070,1070],"y":[66,78,94,117,138,163,173,186,190,188,180,170,161,148,148,148,141,144,144,57,78,105,127,141,158,160,163,166,171,175,185,193,202,207,211,216,227,238,255,268,273,276,276,148,148,152,155,155,155,155,152,148,148,149,152,152,152,157,155,46,58,71,83,101,110,122,130,154,166,175,192,196,198,205,209,217,224,231,233,237,244,250,256,259,256,261,261]},{"x":[547,547,547,547,547,547,547,547,547,554,575,617,655,676,696,712,721,729,727,629,632,637,641,645,649,649,649,653,653,653,657,657,657,657,657,657,661,661,661,661,661,661,661,762,767,777,790,807,824,854,881,904,933,947,960,968,972,972,972,1035,1035,1039,1043,1047,1050,1050,1054,1058,1062,1062,1062,1062,1062,1066,1066,1066,1066,1066,1066,1066,1066,1066,1066,1066,1070,1070,1070],"y":[66,78,94,117,138,163,173,186,190,188,180,170,161,148,148,148,141,144,144,57,78,105,127,141,158,160,163,166,171,175,185,193,202,207,211,216,227,238,255,268,273,276,276,148,148,152,155,155,155,155,152,148,148,149,152,152,152,157,155,46,58,71,83,101,110,122,130,154,166,175,192,196,198,205,209,217,224,231,233,237,244,250,256,259,256,261,261]},{"x":[547,547,547,547,547,547,547,547,547,554,575,617,655,676,696,712,721,729,727,629,632,637,641,645,649,649,649,653,653,653,657,657,657,657,657,657,661,661,661,661,661,661,661,762,767,777,790,807,824,854,881,904,933,947,960,968,972,972,972,1035,1035,1039,1043,1047,1050,1050,1054,1058,1062,1062,1062,1062,1062,1066,1066,1066,1066,1066,1066,1066,1066,1066,1066,1066,1070,1070,1070],"y":[66,78,94,117,138,163,173,186,190,188,180,170,161,148,148,148,141,144,144,57,78,105,127,141,158,160,163,166,171,175,185,193,202,207,211,216,227,238,255,268,273,276,276,148,148,152,155,155,155,155,152,148,148,149,152,152,152,157,155,46,58,71,83,101,110,122,130,154,166,175,192,196,198,205,209,217,224,231,233,237,244,250,256,259,256,261,261]},{"x":[547,547,547,547,547,547,547,547,547,554,575,617,655,676,696,712,721,729,727,629,632,637,641,645,649,649,649,653,653,653,657,657,657,657,657,657,661,661,661,661,661,661,661,762,767,777,790,807,824,854,881,904,933,947,960,968,972,972,972,1035,1035,1039,1043,1047,1050,1050,1054,1058,1062,1062,1062,1062,1062,1066,1066,1066,1066,1066,1066,1066,1066,1066,1066,1066,1070,1070,1070],"y":[66,78,94,117,138,163,173,186,190,188,180,170,161,148,148,148,141,144,144,57,78,105,127,141,158,160,163,166,171,175,185,193,202,207,211,216,227,238,255,268,273,276,276,148,148,152,155,155,155,155,152,148,148,149,152,152,152,157,155,46,58,71,83,101,110,122,130,154,166,175,192,196,198,205,209,217,224,231,233,237,244,250,256,259,256,261,261]}]}],"xDPI":96,"yDPI":96}

 And please find the image of the input given and the output provided.

Thanks and regards

image

image

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.


Best regards,


Olivier