Fast screen capture in python. 2016년 10월 5일 수요일

프로그래밍/english 2016. 12. 3. 23:45

I need to screen capture to make simple macro program.

First, I use ImageGrab in pillow or pyscreenshot.
But, These are too slow for my program.

Then, I found good library-wx.
wx is GUI development library based on C++.
Capture method in wx is more faster than ImageGrab.

But, on pixel processing using pillow methods, PNG is on error.
I don't know why it is, BMP is ok.

Sample code in python.

import time
import pyscreenshot as ImageGrab
import wx
from PIL import Image


def main():
    count = 10
  
    start = time.time()
    for i in xrange(count):
        im = ImageGrab.grab(bbox=(0, 0, 100, 100))
        im.save('ImageGrab.png')
      
    print time.time() - start

    start = time.time()
    app = wx.App()
    screen = wx.ScreenDC()
    for i in xrange(count):
        bmp = wx.EmptyBitmap(100, 100)
        mem = wx.MemoryDC(bmp)
        mem.Blit(0, 0, 100, 100, screen, 0, 0)
        del mem
        bmp.SaveFile('wx.bmp', wx.BITMAP_TYPE_BMP)
      
    print time.time() - start


if __name__ == '__main__':
    main()


Get 0,0 to 100,100 screen image and save it 10 times.

Execute results.

17.631000042
0.203000068665

In my computer, wx is faster than pyscreenshot about 80 times.
If you need to fast screen capture, use wx.

wx install url:
https://wxpython.org/download.php

설정

트랙백

댓글

Using GPIO in Raspberry pi 2016년 9월 21일 수요일

프로그래밍/english 2016. 12. 3. 23:43

GPIO(General Purpose Input Output)




Some sensor is necessary a breadboard

The basic use of sensor is connecting 5V and GND to a sensor(or a breadboard),
then select data line for data sending.
(#4, #17, #18... etc)


You can use GPIO in raspberry using RPi.GPIO Module in python.

python code


# -*- coding: utf8 -*-

from RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUB_UP)

print GPIO.input(4)


The example displays data reading from #4.
You can process various data from sensor.
(Fire sensor, Temperature sensor...)


설정

트랙백

댓글