Commit 2242bd73 authored by ranthilina99's avatar ranthilina99

update growth height and python

parent 15680fad
/build /build
/src/main/assets /src/main/assets/model.tflite
\ No newline at end of file \ No newline at end of file
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.EKetha"> android:theme="@style/Theme.EKetha">
<activity android:name=".SplashScreen" <activity
android:name=".SplashScreen"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
...@@ -33,10 +34,9 @@ ...@@ -33,10 +34,9 @@
<activity android:name=".GrowthThreatment" /> <activity android:name=".GrowthThreatment" />
<activity android:name=".GrowthDetect" /> <activity android:name=".GrowthDetect" />
<activity android:name=".Admin" /> <activity android:name=".Admin" />
<activity android:name=".growthHome" />
<activity android:name=".Growth" /> <activity android:name=".Growth" />
<activity android:name=".Register" /> <activity android:name=".Register" />
<activity android:name=".Login"/> <activity android:name=".Login" />
<activity android:name=".MainActivity" /> <activity android:name=".MainActivity" />
<provider <provider
......
...@@ -13,6 +13,7 @@ import android.util.Base64; ...@@ -13,6 +13,7 @@ import android.util.Base64;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.Toast;
import com.chaquo.python.PyObject; import com.chaquo.python.PyObject;
import com.chaquo.python.Python; import com.chaquo.python.Python;
...@@ -21,6 +22,8 @@ import com.chaquo.python.android.AndroidPlatform; ...@@ -21,6 +22,8 @@ import com.chaquo.python.android.AndroidPlatform;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class GrowthHeight extends AppCompatActivity { public class GrowthHeight extends AppCompatActivity {
...@@ -127,13 +130,25 @@ public class GrowthHeight extends AppCompatActivity { ...@@ -127,13 +130,25 @@ public class GrowthHeight extends AppCompatActivity {
PyObject pyo = py.getModule("height"); PyObject pyo = py.getModule("height");
PyObject obj = pyo.callAttr("main", imageString); PyObject obj = pyo.callAttr("main", imageString);
//System.out.println("-----------------------------------");
System.out.println(obj);
// ArrayList<PyObject> arrayList = new ArrayList<PyObject>();
// System.out.println("-----------------------------------");
// arrayList.add(obj);
// System.out.println(arrayList);
String str = obj.toString(); String str = obj.toString();
//System.out.println("-----------------------------------");
byte data[] = Base64.decode(str, Base64.DEFAULT); //System.out.println(obj);
//System.out.println(str);
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length); //System.out.println("33333333333333333333333333333333333 ");
if(str.equals("abc")){
outputImage = bmp; Toast.makeText(this, "Please upload quality image", Toast.LENGTH_SHORT).show();
// Intent intent = new Intent(GrowthHeight.this, growthHome.class);
// startActivity(intent);
}else{
byte data[] = Base64.decode(str, Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
outputImage = bmp;
}
} }
} }
\ No newline at end of file
...@@ -36,35 +36,38 @@ def main(data): ...@@ -36,35 +36,38 @@ def main(data):
cnts = imutils.grab_contours(cnts) cnts = imutils.grab_contours(cnts)
(cnts, _) = contours.sort_contours(cnts) (cnts, _) = contours.sort_contours(cnts)
cnts = [x for x in cnts if cv2.contourArea(x) >2000] cnts = [x for x in cnts if cv2.contourArea(x) >2000]
ref_object = cnts[0] if len(cnts)>0 :
box = cv2.minAreaRect(ref_object) ref_object = cnts[0]
box = cv2.boxPoints(box) box = cv2.minAreaRect(ref_object)
box = np.array(box, dtype="int")
box = perspective.order_points(box)
(tl, tr, br, bl) = box
dist_in_pixel = euclidean(tl, tr)
dist_in_cm =10
pixel_per_cm = dist_in_pixel/dist_in_cm
for cnt in cnts:
box = cv2.minAreaRect(cnt)
box = cv2.boxPoints(box) box = cv2.boxPoints(box)
box = np.array(box, dtype="int") box = np.array(box, dtype="int")
box = perspective.order_points(box) box = perspective.order_points(box)
(tl, tr, br, bl) = box (tl, tr, br, bl) = box
cv2.drawContours(out_img, [box.astype("int")], -1, (0, 0, 255), 2) dist_in_pixel = euclidean(tl, tr)
mid_pt_horizontal = (tl[0] + int(abs(tr[0] - tl[0])/2), tl[1] + int(abs(tr[1] - tl[1])/2)) dist_in_cm =10
mid_pt_verticle = (tr[0] + int(abs(tr[0] - br[0])/2), tr[1] + int(abs(tr[1] - br[1])/2)) pixel_per_cm = dist_in_pixel/dist_in_cm
wid = euclidean(tl, tr)/pixel_per_cm for cnt in cnts:
ht = euclidean(tr, br)/pixel_per_cm box = cv2.minAreaRect(cnt)
cv2.putText(out_img, "{:.1f}cm".format(ht), (int(mid_pt_verticle[0] + 10), int(mid_pt_verticle[1])), box = cv2.boxPoints(box)
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 5), 2) box = np.array(box, dtype="int")
box = perspective.order_points(box)
(tl, tr, br, bl) = box
cv2.drawContours(out_img, [box.astype("int")], -1, (0, 0, 255), 2)
mid_pt_horizontal = (tl[0] + int(abs(tr[0] - tl[0])/2), tl[1] + int(abs(tr[1] - tl[1])/2))
mid_pt_verticle = (tr[0] + int(abs(tr[0] - br[0])/2), tr[1] + int(abs(tr[1] - br[1])/2))
wid = euclidean(tl, tr)/pixel_per_cm
ht = euclidean(tr, br)/pixel_per_cm
cv2.putText(out_img, "{:.1f}cm".format(ht), (int(mid_pt_verticle[0] + 10), int(mid_pt_verticle[1])),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 5), 2)
pil_img = Image.fromarray(out_img) pil_img = Image.fromarray(out_img)
buff = io.BytesIO() buff = io.BytesIO()
pil_img.save(buff, format="JPEG") pil_img.save(buff, format="JPEG")
#encode the image #encode the image
img_str = base64.b64encode(buff.getvalue()) img_str = base64.b64encode(buff.getvalue())
return ""+str(img_str, 'utf-8') return ""+str(img_str, 'utf-8')
\ No newline at end of file else :
return "abc"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment