Python: OpenCV: resize image fit to your screen

25 02 2019

OpenCV can display image but if your image bigger than your screen or your display window you can’t see all your image. this code will detect display size and resize your image to fit on it. come and see

# Created: 25/02/2019
# Copyright: (c) PNU 2019
import cv2
import ctypes

## get Screen Size
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)

def showImage(filename):
     W,H = screensize
     oriimg = cv2.imread(filename,cv2.CV_LOAD_IMAGE_COLOR)
     height, width, depth = oriimg.shape

     scaleWidth = float(W)/float(width)
     scaleHeight = float(H)/float(height)
     if scaleHeight>scaleWidth:
          imgScale = scaleWidth
          imgScale = scaleHeight

     newX,newY = oriimg.shape[1]*imgScale, oriimg.shape[0]*imgScale
     newimg = cv2.resize(oriimg,(int(newX),int(newY)))
     cv2.imshow("fit image to screen by CV2",newimg)

if __name__ == '__main__':
     filename = 'bigImage.jpg'

there are some windows taskbar so image can’t display full screen I think use 90% of scree size is good to display.
enjoy this code.


Install .whl package for Python on Windows

22 02 2019

Python need extension package to do many thing. Now package distribute in wheel file (.whl).The most popular way to install the new Python package or library is to use PIP. After install Python in your machine you need to install pip

OS: windows 10 [64bit]
Python: Python 2.7  [download link: ]

install pip:

c:> cd python27
c:Python27>python D:\Softwares\Python2.7-package\


  • add python script path to the system variable path by open control panel and click little arrow after control panel and select All Control Panel Item


on left menu select Advanced system settings 


click Environment Variables… 


it show Environment Variables box. Select Path in System variables then click Edit…


click at last row and type your Scripts in Python folder the click OK all


  • now you can install whl package by go to whl download file and type
pip install your whl file


Enjoy your python

download python package here


Toyota Starlet EP-71 Rear Wiper Motor Diagram

13 07 2018

I want to change my Back door car from normal to back door with wiper. Toyota Starlet EP-71 was difficult to find diagram, here I show diagram here it should be work with many rear wiper if it come with wiper control.

This diagram drawing in Inkscape software, it’s work well and absolute FREE

EP71 rear wiper motor

ตามหาผังการต่อสายไฟของที่ปัดน้ำฝนหลังของ โตโยต้า สตาร์เลท EP-71 มานาน เนื่องจากไม่ได้ต่อไฟเข้ามอเตอร์ธรรมดา มีกล่องควบคุมแยกต่างหากด้วย หาไม่ได้ซักที เลยเชิญผู้เชี่ยวชาญด้านอิเลกทรอนิกส์ยานยนต์มาไล่สายให้ สรุปเป็นผังไว้ใช้งานได้แบบนี้ครับ  ถ้าใช้งานได้ดี แจ้งกันบ้าง ถ้ามีปัญหารีบแจ้งเลยครับ เน้อะ

Lost capacity in MicroSD card

15 06 2016

I have 16 GB microSD card use in Windows and Ubuntu. When I want to format this card Windows can read only 70.4 MB, Oh it lost a lot. I think Windows can’t read some Linux files. OK let’s clean it up.

เนื้อที่ใน microSD การ์ด อยู่ ๆ ก็หายไปเฉย อย่าเพิ่งตกใจลองทำตามวิธีนี้ก่อน


With “DiskPart” software in Windows, This work will run in command line, don’t worry it will show step by step. Click on Start menu (Windows logo) and type “diskpart” then click diskpart program.


The DiskPart dialog box will show up.


Then follow this step by step

  1. list your disk by type “list disk” then enter. it will show all of your disk in your computer.  for example I have 500 GB HDD, 8 GB boot up disk and 16 GB microSD. it will show Disk 0 Disk 1 and Disk 2 my 16 GB microSD located in Disk 2.
  2. Select disk (Disk 2 for me) by type “select disk 2” and enter.
  3. now clean their space by type “clean” then enter.
  4. next create partition by type “create partition primary” then enter.
  5. go to new partition by type “select partition 1” then enter.
  6. set active by type “active” then enter.
  7. format it by type “format fs-ntfs quick” then enter and wait until format finish.
  8.  assign dike for use by type “assign” then enter.
  9. finish. you can exit diskpart by type “exit” and click enter.

the response should be like this image.


Now Windows can see 14.4 GB on microSD disk.


Python: Read Excel file

14 07 2014

read data in excel by python using xlrd plugin

import xlrd
xlsName = "data.xls"
book = xlrd.open_workbook(xlsName)
print "The Number of worksheets is ", book.nsheets
print "Worksheet name(s):", book.sheet_names()
sht = len(book.sheet_names())
for i in range(sht):
   sh = book.sheet_by_index(i)
   print "%s have %d rows %d columns"%(, sh.nrows, sh.ncols)
worksheet = book.sheet_by_index(0)
header_row = 0
headers = [worksheet.cell_value(header_row,i) for i in xrange(worksheet.ncols)]
print headers
def getVal(raw,row,col):
   if raw == xlrd.XL_CELL_EMPTY:
     value = None
   elif raw == xlrd.XL_CELL_TEXT:
     value = worksheet.cell_value(row, col)
   elif raw == xlrd.XL_CELL_NUMBER:
     value = float(worksheet.cell_value(row,col))
   elif raw == xlrd.XL_CELL_DATE:
     value = xlrd.xldate_as_tuple(worksheet.cell_value(row, col), workbook.datemode)
   elif raw == xlrd.XL_CELL_BOOLEAN:
     value = bool(worksheet.cell_value(row, col))
     value = worksheet.cell_value(row, col)
row_dict_list = []
for row in xrange(header_row+1, worksheet.nrows):
   rowData = [worksheet.cell_value(row,i) for i in xrange(worksheet.ncols) ]

the result show:

The Number of worksheets is 2
Worksheet name(s): [u’Sheet4′, u’Sheet5′]
Sheet4 have 121 rows 6 columns
Sheet5 have 0 rows 0 columns
[u’No.’, u’NAME’, u’DISTANCE (M)’, u’P&L’, u’TRANSACTION’, u’DOWNTME’]

Python: OpenCV: resize image by width

6 07 2014

resize big image by width for example there are 5400×2700 pixels and want to display by 1000 pixel width. try this
import cv2
filename = 'bigimage.jpg'
W = 1000.
oriimg = cv2.imread(filename,cv2.CV_LOAD_IMAGE_COLOR)
height, width, depth = oriimg.shape
imgScale = W/width
newX,newY = oriimg.shape[1]*imgScale, oriimg.shape[0]*imgScale
newimg = cv2.resize(oriimg,(int(newX),int(newY)))
cv2.imshow("Show by CV2",newimg)

if image has width less than 1000 it will be enlarge image.

Python: Install OWSLib package on windows 7 64 bit

21 04 2014


OWSLib is a Python package for client programming with Open Geospatial Consortium (OGC) web service (hence OWS) interface standards, and their related content models. There are no binary package for windows but you can use this way to install.


step 1:

you need to install easy_install.exe it come with setuptools package. download setuptools link

after install setuptools you will have c:\Python27\Scripts\easy_inistall.exe


step 2:

open command prompt (terminal window) [how to open command prompt ]

type this in command prompt window

C:\>cd Python27\Scripts
C:\Python27\Scripts>easy_install.exe OWSLib


when this message show that mean package installed

Finished processing dependencies for OWSLib


now you can test OWSLib by follow tutorial [Tutorial OWSLib]

enjoy! or leave comment 🙂