Where the mind is without fear..
plugins {
id 'com.chaquo.python' version '14.0.2' apply false
}
// Top-level build file where you can add configuration options
// common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id 'com.chaquo.python' version '14.0.2' apply false
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
plugins{
id 'com.android.application'
id 'com.chaquo.python'
}
ndk{
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
defaultConfig {
ndk{
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
Python {
buildPython "C:/Users/XXXX/AppData/Local/Programs/Python/Python311/python.exe"
}
}
android {
ndkVersion "22.1.7171670"
defaultConfig {
minSdkVersion 21
ndk{
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
Python {
buildPython "C:/Users/xxxx/AppData/Local/Programs/Python/Python311/python.exe"
pip {
install "numpy"
install "patchify"
install "pillow"
install "opencv-python"
}
}
}
}

android{
sourceSets{
main{
python.srcDir “path/to/dir”
}
}
}
if(!Python.isStarted()){
Python.start(new AndroidPlatform(getApplicationContext()));
}
//obtain the python instance
py = Python.getInstance();
package me.example.test;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.Toast;
import com.chaquo.python.PyObject;
import com.chaquo.python.Python;
import com.chaquo.python.android.AndroidPlatform;
public class MyActivity extends AppCompatActivity {
private Python py;
private Button btnMath;
private Button btnShowButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
Intent getImage = getIntent();
//instantiate the Button with id btnDoMath decleared in xml
//layout file activity_my
btnMath = findViewById(R.id.btnDoMath);
btnMath.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String res = getMaths();
Toast.makeText(MyActivity.this, res, Toast.LENGTH_LONG).show();
}
});
//instantiate the Button with id btnShowButton decleared in xml
//layout file activity_my
btnShowButton = findViewById(R.id.btnShowButton);
btnShowButton.setOnClickListener(new View.onClickListener(){
@Override
public void onClick(View v){
String show = showButtonPosition("Apple, Mango, Button, Guava, Button");
Toast.makeText(MyActivity.this, show, Toast.LENGTH_LONG).show();
}
});
if(!Python.isStarted()){
Python.start(new AndroidPlatform(getApplicationContext()));
}
//obtain the python instance
py = Python.getInstance();
dispStat = findViewById(R.id.dispStat);
}
private String showButtonPosition(String inText){
PyObject myObj = py.getModule("mytest");
PyObject result = myObj.callAttr("findFirstButton", inText);
List list = result.asList();
PyObject output = list.get(0);
int position = output.toInt();
String printRes = "First occurance of Button in the string is at "+position;
return printRes;
}
private String getMaths(int v1, int v2){
PyObject sys = py.getModule("sys");
PyObject is = py.getModule("io");
PyObject myObj = py.getModule("mytest");
PyObject result = myObj.callAttr("returnMath", v1,v2);
List list = result.asList();
PyObject res1 = list.get(0);
PyObject res2 = list.get(1);
PyObject res3 = list.get(2);
String str1 = res1.toString();
String str2 = res2.toString();
String str3 = res3.toString();
String printRes = "Multiplication :"+ str1;
printRes += "\nAddition: "+ str2;
printRes += "\nSum of squares: "+ str3;
return printRes;
}
}
import numpy as np
from patchify import patchify
import cv2
#import opencv-python
#%matplotlib inline
#the function below is just an example
def getBinary(image_gr_ByteArr,threshold,height):
patches= []
thresh = 90
decode = cv2.imdecode(np.asarray(image_gr_ByteArr),cv2.IMREAD_UNCHANGED)
encode = cv2.imencode('.png', image_bw)[1]
data_encode = np.array(encode)
return data_encode.tobytes(), threshold
def returnMath(val1, val2):
res1 = val1*val2
res2 = val1 + val2
res3 = val1**2 + val2**2
return res1,res2,res3
def findFirstButton(sentence):
first_index = sentence.find('Button')
return first_index
