Tuesday, August 11, 2015

raspberry pi 進入X-window自動執行腳本

如果您使用的Raspbian操作系統在你的樹莓派,你會知道,當你鍵入startx就啟動該圖形用戶界面“LXDE”。在這樣的環境中也有大量的應用程序和工具。在你的項目,你可能想要自動加載的一個或多個這些應用程序在運行startx的,以節省您不必手動啟動它們。

自動啟動程序
vi .config/lxsession/LXDE-pi/autostart

執行.sh腳本
@/bin/sh /home/pi/opencv_script.sh


參考資料:
http://www.raspberrypi-spy.co.uk/2014/05/how-to-autostart-apps-in-rasbian-lxde-desktop/

Wednesday, August 5, 2015

用滑鼠再圖片上畫框框

import cv2
import numpy as np
global px,py    

drawing = False # true if mouse is pressed
mode = True # if True, draw rectangle. Press 'm' to toggle to curve
ix,iy = -1,-1

# mouse callback function
def draw_circle(event,x,y,flags,param):
    
    global ix,iy,drawing,mode
    #Click 
    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        ix,iy = x,y
        print "ix=",ix,"iy=",iy

    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False
        if mode == True:
  cv2.rectangle(img,(ix,iy),(x,y),(0,255,255),0)

img = cv2.imread('room.jpg')
cv2.namedWindow('image')
cv2.setMouseCallback('image',draw_circle)

while(1):
 
    cv2.imshow('image',img)
    k = cv2.waitKey(1) & 0xFF
    if k == ord('m'):
        mode = not mode
    elif k == 27:
        break

cv2.destroyAllWindows()