hope you all can help me in someway.
I'm a newby in python and I'm tring to make a Kivy app. As the title says, my app works perfectly on my pc but, as soon as I open it on my android it crashes (on the loading screen). I know how to debug the app and how to use kivy launcher, i've already tested some apps, but this one has an issue that i don't know how to fix.
What i'm tring to do is:
pickup an image;
transform it into an numpy array;
select an circular area of the image and save the pixels of this area into a new list;
calculate the mean value of the pixels and classify the image according to some parameters.
Again, I can do all this things on my pc (but if someone has something that would help me to improve me coding skills... I'd be glad to hear some tips).
The issue seems to be on the way I try to open the image inside my code, but I really don't know why since the directory of the image is the same as the one my main.py is saved, so i though i just needed to open the image as always (indicating the name of the file).
here is my code:
#-*- coding: utf-8 -*-
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
kivy.require('1.9.1')
class MeuApp(App):
def build(self):
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import math
img = r"C:\Users\Carlos Foiani\Dropbox\My PC (NOT-CAVIOLA)\Desktop\Letícia\UFABC\Pesquisa\PDPD -2020\24.02.2021\Todas\CN 9_3 - cor.jpg"
# Leitura da fotografia
foto = mpimg.imread(img)
linhas = len(foto)
colunas = len(foto[0])
array_pixels = np.array(foto)
lista_pixels = array_pixels.tolist()
dentro = []
# Desenho de um círculo
for i in range(linhas):
for j in range(colunas):
if (i - linhas // 2) ** 2 + (j - colunas // 2) ** 2 <= (colunas // 2) ** 2:
dentro.append(lista_pixels[i][j])
else:
foto[i, j] = sum(foto[i, j]) / 3 - 0.5
# Visualizar a fotografia
plt.imshow(foto)
plt.show()
raio = (colunas // 2)
area = np.pi * (raio ** 2)
OD = math.log((255 / (np.mean(dentro))), 10)
ODI = OD * area
a = "[b]Intensidade média de luz transmitida pela imagem:[/b] " + str(np.mean(dentro)) + " \n"
b = "\n [b]Área:[/b] " + str(area) + " μm \n"
c = "\n [b]Densidade óptica:[/b] " + str(OD) + " \n"
d = "\n [b]Densidade óptica integrada:[/b] " + str(ODI) + " \n"
if ODI < 674353.78:
e = "\n Essa amostra faz parte do grupo [b]POSITIVO[/b] para carcinoma \n"
return Label(text=a+b+c+d+e, markup=True)
elif ODI > 674353.78:
e = "\n Essa amostra faz parte do grupo [b]NEGATIVO[/b] para carcinoma \n"
return Label(text=a+b+c+d+e, markup=True)
if __name__ == '__main__':
MeuApp().run()
Heres is what I expect to see on the smartphone (and what I'm getting on my pc
I've tried opening the image usem some kivy libraries (such as kivy.uix.image) but they doesn't let me transform the image into an array.
This is just the first version of the app, but I need it to run on android as soon as possible so that I can use it as a result for my research. I intend to make this better, just not now.
thanks in advance for any kind of help!