Python 3 Kivy OpenCV Image Converter GUI Script Desktop App Full Project For Beginners

Python 3 Kivy OpenCV Image Converter GUI Script Desktop App Full Project For Beginners

 

Welcome folks today in this tutorial we will be building a kivy image converter app using opencv library in python. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to install the following libraries using the pip command as shown below

`

pip install kivy

 

pip install opencv-python

 

After installing these libraries you need to make an app.py file and copy paste the following code

 

app.py

 

from kivy.core.window import Window
Window.size = (350, 600)
from kivy.config import Config
Config.set('graphics','resizable',0)

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.label import Label
import cv2






kv = '''
main:
    BoxLayout:
        orientation: 'vertical'
        padding: root.width * 0.05, root.height * .05
        BoxLayout:
            size_hint: [1,.3]
            orientation: 'horizontal'
            Image:
                source: 'image.jpg'
            Label:
                text: "Image Convert"
                bold: True
        BoxLayout:
            size_hint: [1,.7]
            GridLayout:
                spacing: '10dp'
                cols: 1
                Label:
                    text: 'Source'
                TextInput:
                    id:source
                Label:
                    text: 'Name and Extension'
                GridLayout:
                    cols: 2
                    spacing: '3dp'
                    TextInput:
                        id:dest
                    Spinner:
                        id: ext
                        text: '.jpg'
                        bold: True
                        background_normal: 'blue.jpg'
                        values: ('.jpg', '.png', '.bmp', '.gif')
                Button:
                    text: "Convert"
                    bold: True
                    background_normal: 'red.jpg'
                    on_press: root.convert()

'''
class main(BoxLayout):
    def convert(self):
        source = self.ids.source.text
        dest  = self.ids.dest.text
        ext = self.ids.ext.text
        destination_filename = dest+ext
        try:
            image = cv2.imread(source)
            cv2.imwrite(destination_filename, image)
            popup = Popup(title='Done', content=Label(text='Image Converted'),size_hint=(.5, .2))
            popup.open()
        except:
            popup = Popup(title='Error', content=Label(text='Error converting'), size_hint=(.5, .2))
            popup.open()


class imageConvert(App):
    def build(self):
        return Builder.load_string(kv)

imageConvert().run()

 

See also  Python 3 Tkinter Close Window Using root.Destroy() Method Using Button inside Functions and Classes in GUI Desktop App Full Project For Beginners

 

Now if you execute the python script by typing the below command as shown below

 

python app.py

 

 

 

 

 

Leave a Reply