Opencv Image on Kivy Image() Widget

530 views
Skip to first unread message

Mateus Michels

unread,
Oct 8, 2018, 10:57:58 AM10/8/18
to Kivy users support
Hello, that's my first post, before you think "Alrealy exist a post with that topic" sorry, i din't find that.

Thats my problem, i'm trying to put a image processed on yolo with opencv, this image is a instance of a cv2.imread, i have found many examples with camera but dosen't work for me.

The idea is to get a image file on the computer and show it on a Image() widget, after that, the program send exactly the same image to a darknet (yolo) object detection, after the detection, this image will be saved on the same variable of the input, and so, the program must to take that image (remains a cv2.imread return) and show the result on the same Image() widget.

But it is resulting in a black screen...

Based on a kivy opencv camera example i reach on that code:


class Imagem(Image):
def build(self):
return Image()

def atualizaImagem(self, img):
imagem = img # cv2.imread image
buf1 = cv2.flip(imagem, 0)
buf = buf1.tostring()
texture1 = Texture.create(size=(imagem.shape[1], imagem.shape[0]), colorfmt='bgr')
texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
self.texture = texture1 # ends with a black image.

this object is what i use to build and manipulate a Image() widget. on another aplication that works, but in this no... (On another code is a simple Image() and Button(), when button is pressed the 'atualizarImage()' is runned.)

Maybe the problem is in a Image() widget be inside another boxLayout()?

Mateus Michels

unread,
Oct 8, 2018, 11:08:18 AM10/8/18
to Kivy users support
ATT: Reading the Logs file i found that: Shader: GL error 1282, it appers after that line be runned: "texture1 = Texture.create(size=(imagem.shape[1], imagem.shape[0]), colorfmt='bgr')"

Mateus Michels

unread,
Oct 8, 2018, 11:12:35 AM10/8/18
to Kivy users support
Problem happens because i'm runing that code in a
separate thread

Em segunda-feira, 8 de outubro de 2018 11:57:58 UTC-3, Mateus Michels escreveu:

Sato Takenori

unread,
Oct 8, 2018, 6:42:02 PM10/8/18
to kivy-...@googlegroups.com
Hi,

I have used OpenCV 3.x ~ 3.4.2 on Kivy 1.10.0 and 1.10.1 
in the way by loading OpenCV image as a Texture of Image.
My method of texture creation is as follows.

    def texture_from_opencv(self, frame, colorfmt='bgr'):
        resolution = (int(frame.shape[1]), int(frame.shape[0]))
        texture = Texture.create(resolution)
        texture.flip_vertical()

        texture.blit_buffer(frame.tostring(), colorfmt=colorfmt)

        return texture

As you can see, this does basically the same thing as yours.

> Problem happens because i'm runing that code in a 
> separate thread
Do you use Process in addition to Threading?

For example, I run an expensive method(e.g. GPU object detection) in a separate Process.
In such a case, you need to make sure any thread is created after Process creations 
because Python on Linux uses a fork to create a new Process 
that copies existing threads of its parent Process,
which would lead to ugly dead locking issues.
It is often suggested in SDL/OpenGL communities.

Try enabling more verbose debugging.

2018年10月9日(火) 0:12 Mateus Michels <thi...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/41b75399-dd4d-4c42-bbd0-8ec4f436f743%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gregori Alberto Rovadoscki

unread,
Sep 27, 2023, 10:17:29 AM9/27/23
to Kivy users support
Were you able to run Yolo on Kivy?

Gregori Alberto Rovadoscki

unread,
Sep 27, 2023, 10:21:33 AM9/27/23
to Kivy users support
Were you able to run Yolo on Kivy APK?
Message has been deleted

Robert

unread,
Sep 27, 2023, 1:06:32 PM9/27/23
to Kivy users support
Rather than fight the opencv camera in Android (I don't think it works) take a look at this object detection example:
https://github.com/Android-for-Python/c4k_tflite_example

Or the same architecture using opencv image processing, just not Yolo
https://github.com/Android-for-Python/c4k_opencv_example

Gregori Alberto Rovadoscki

unread,
Sep 27, 2023, 1:44:00 PM9/27/23
to kivy-...@googlegroups.com
great, tflite works with instance segmentation??

You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/gYshTZjlfg4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d21c76ea-a2da-433d-85b3-0ef6fb0b93ebn%40googlegroups.com.


--
Gregori Rovadoscki
Bacharel em Zootecnia - UDESC
Mestre em Ciências - ESALQ/USP
Doutor em Ciências - ESALQ/USP
Piracicaba - São Paulo

Robert

unread,
Sep 27, 2023, 3:29:06 PM9/27/23
to Kivy users support
No clue what the even means 🤣

Gregori Alberto Rovadoscki

unread,
Sep 27, 2023, 3:34:55 PM9/27/23
to kivy-...@googlegroups.com
No problem, you help me a lot. I really appreciate your attention.....

Reply all
Reply to author
Forward
0 new messages