├── PiCameraGUI.py ├── README.md ├── screen002.jpg ├── screenshot.jpg └── zoomed.jpg /PiCameraGUI.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import time 3 | import pygame 4 | from pygame.locals import * 5 | import os, sys 6 | import datetime 7 | import subprocess 8 | import signal 9 | import cv2 10 | 11 | # version 17 12 | 13 | 14 | # set displayed preview image size (must be less than screen size to allow for menu!!) 15 | # recommended 640x480, 800x600, 1280x960 16 | preview_width = 640 17 | preview_height = 480 18 | 19 | # set default limits 20 | mode = 1 # set camera mode ['off','auto','night' etc] 21 | speed = 13 # position in shutters list 22 | ISO = 0 # 0 = auto or 100,200,400,800 23 | brightness = 50 # set camera brightness 24 | contrast = 0 # set camera contrast 25 | ev = 0 # eV correction 26 | blue = 1.2 # blue balance 27 | red = 1.5 # red balance 28 | extn = 0 # still file type 29 | vlen = 10 # video length in seconds 30 | fps = 25 # video fps 31 | vformat = 4 # set video format 32 | a_video = 0 # set to 1 to annotate date and time on video, set to 2 for showing shutter speed etc 33 | tinterval = 60 # time between timelapse shots in seconds 34 | tshots = 20 # number of timelapse shots 35 | frame = 0 # set to 1 for no frame (i.e. if using Pi 7" touchscreen) 36 | effect = 0 # picture effects 37 | meter = 0 # metering mode 38 | awb = 0 # auto white balance mode 39 | flicker = 0 # reduce mains flicker, 0-3 = off, auto, 50Hz, 60Hz 40 | drc = 0 # dynamic range compression, 0-3 = off,low,med,high 41 | 42 | # NOTE if you change any of the above still_limits you need to delete the config_file and restart. 43 | 44 | # default directories and files 45 | pic_dir = "/home/pi/Pictures/" 46 | vid_dir = "/home/pi/Videos/" 47 | config_file = "/home/pi/PiConfig5.txt" 48 | 49 | # inital parameters 50 | zx = int(preview_width/2) 51 | zy = int(preview_height/2) 52 | zoom = 0 53 | igw = 2592 54 | igh = 1944 55 | zwidth = igw 56 | zheight = igh 57 | tduration = tinterval * tshots 58 | # set button sizes 59 | bw = int(preview_width/8) 60 | bh = int(preview_height/13) 61 | ft = int(preview_width/52) 62 | fv = int(preview_width/52) 63 | 64 | # data 65 | modes = ['off','auto','night','nightpreview','backlight','spotlight','sports','snow','beach','verylong','fixedfps','antishake','fireworks'] 66 | extns = ['jpg','png','bmp','gif'] 67 | vwidths = [640,800,1280,1280,1440,1920] 68 | vheights = [480,600, 720, 960,1080,1080] 69 | v_max_fps = [90 , 40, 40, 40, 40, 30] 70 | shutters = [-2000,-1600,-1250,-1000,-800,-640,-500,-400,-320,-288,-250,-240,-200,-160,-144,-125,-120,-100,-96,-80,-60,-50,-48,-40,-30,-25,-20,-15,-13,-10,-8,-6,-5,-4,-3, 71 | 0.4,0.5,0.6,0.8,1,2,3,4,5,6,7,8,9,10,15,20,25,30,40,50,60,75,100,120,150,200,220,239] 72 | effects = ['none','negative','solarise','posterise','whiteboard','blackboard','sketch','denoise','emboss','oilpaint','hatch','gpen','pastel','watercolour','film','blur','saturation'] 73 | meters = ['average','spot','backlit','matrix'] 74 | awbs = ['off','auto','sun','cloud','shade','tungsten','fluorescent','incandescent','flash','horizon','greyworld'] 75 | flickers = ['off','auto','50Hz','60Hz'] 76 | drcs = ['off','low','med','high'] 77 | still_limits = ['mode',0,len(modes)-1,'speed',0,len(shutters)-1,'ISO',0,800,'brightness',0,100,'contrast',-100,100,'ev',-12,12,'blue',0.1,8,'red',0.1,8,'extn',0,len(extns)-1,'effect',0,len(effects)-1,'meter',0,len(meters)-1,'awb',0,len(awbs)-1] 78 | video_limits = ['vlen',1,999,'fps',2,40,'vformat',0,len(vwidths)-1,'0',0,0,'a_video',0,2,'zoom',0,4,'Focus',0,1,'tduration',1,9999,'tinterval',1,999,'tshots',1,999,'flicker',0,3,'drc',0,3] 79 | 80 | # check PiCconfigX.txt exists, if not then write default values 81 | if not os.path.exists(config_file): 82 | points = [mode,speed,ISO,brightness,contrast,frame,int(red*10),int(blue*10),ev,vlen,fps,vformat,a_video,tinterval,tshots,tduration,extn,zx,zy,zoom,effect,meter,awb,flicker,drc] 83 | with open(config_file, 'w') as f: 84 | for item in points: 85 | f.write("%s\n" % item) 86 | 87 | # read PiCconfigX.txt 88 | config = [] 89 | with open(config_file, "r") as file: 90 | line = file.readline() 91 | while line: 92 | config.append(line.strip()) 93 | line = file.readline() 94 | config = list(map(int,config)) 95 | 96 | mode = config[0] 97 | speed = config[1] 98 | ISO = config[2] 99 | brightness = config[3] 100 | contrast = config[4] 101 | fullscreen = config[5] 102 | red = config[6]/10 103 | blue = config[7]/10 104 | ev = config[8] 105 | vlen = config[9] 106 | fps = config[10] 107 | vformat = config[11] 108 | a_video = config[12] 109 | tinterval = config[13] 110 | tshots = config[14] 111 | tduration = config[15] 112 | extn = config[16] 113 | zx = config[17] 114 | zy = config[18] 115 | zoom = config[19] 116 | effect = config[20] 117 | meter = config[21] 118 | awb = config[22] 119 | flicker = config[23] 120 | drc = config[24] 121 | 122 | vwidth = vwidths[vformat] 123 | vheight = vheights[vformat] 124 | vfps = v_max_fps[vformat] 125 | tduration = tinterval * tshots 126 | 127 | shutter = shutters[speed] 128 | if shutter < 0: 129 | shutter = abs(1/shutter) 130 | sspeed = int(shutter * 1000000) 131 | if (shutter * 1000000) - int(shutter * 1000000) > 0.5: 132 | sspeed +=1 133 | 134 | pygame.init() 135 | if frame == 0: 136 | windowSurfaceObj = pygame.display.set_mode((preview_width + (bw*2),preview_height ), 0, 24) 137 | else: 138 | windowSurfaceObj = pygame.display.set_mode((preview_width + bw,preview_height), pygame.NOFRAME, 24) 139 | pygame.display.set_caption('Pi Camera GUI') 140 | 141 | global greyColor, redColor, greenColor, blueColor, dgryColor, lgrnColor, blackColor, whiteColor, purpleColor, yellowColor,lpurColor,lyelColor 142 | bredColor = pygame.Color(255, 0, 0) 143 | lgrnColor = pygame.Color(162, 192, 162) 144 | lpurColor = pygame.Color(192, 162, 192) 145 | lyelColor = pygame.Color(192, 192, 162) 146 | blackColor = pygame.Color( 0, 0, 0) 147 | whiteColor = pygame.Color(200, 200, 200) 148 | greyColor = pygame.Color(128, 128, 128) 149 | dgryColor = pygame.Color( 64, 64, 64) 150 | greenColor = pygame.Color( 0, 255, 0) 151 | purpleColor = pygame.Color(255, 0, 255) 152 | yellowColor = pygame.Color(255, 255, 0) 153 | blueColor = pygame.Color( 0, 0, 255) 154 | redColor = pygame.Color(200, 0, 0) 155 | 156 | def button(col,row, bkgnd_Color,border_Color): 157 | global preview_width,bw,bh 158 | colors = [greyColor, dgryColor,yellowColor,purpleColor,greenColor,whiteColor,lgrnColor,lpurColor,lyelColor] 159 | Color = colors[bkgnd_Color] 160 | bx = preview_width + (col * bw) 161 | by = row * bh 162 | pygame.draw.rect(windowSurfaceObj,Color,Rect(bx,by,bw-1,bh)) 163 | pygame.draw.line(windowSurfaceObj,colors[border_Color],(bx,by),(bx+bw,by)) 164 | pygame.draw.line(windowSurfaceObj,greyColor,(bx+bw-1,by),(bx+bw-1,by+bh)) 165 | pygame.draw.line(windowSurfaceObj,colors[border_Color],(bx,by),(bx,by+bh-1)) 166 | pygame.draw.line(windowSurfaceObj,dgryColor,(bx,by+bh-1),(bx+bw-1,by+bh-1)) 167 | pygame.display.update(bx, by, bw, bh) 168 | return 169 | 170 | def text(col,row,fColor,top,upd,msg,fsize,bkgnd_Color): 171 | global bh,preview_width,fv 172 | colors = [dgryColor, greenColor, yellowColor, redColor, purpleColor, blueColor, whiteColor, greyColor, blackColor, purpleColor,lgrnColor,lpurColor,lyelColor] 173 | Color = colors[fColor] 174 | bColor = colors[bkgnd_Color] 175 | bx = preview_width + (col * bw) 176 | by = row * bh 177 | if os.path.exists ('/usr/share/fonts/truetype/freefont/FreeSerif.ttf'): 178 | fontObj = pygame.font.Font('/usr/share/fonts/truetype/freefont/FreeSerif.ttf', int(fsize)) 179 | else: 180 | fontObj = pygame.font.Font(None, int(fsize)) 181 | msgSurfaceObj = fontObj.render(msg, False, Color) 182 | msgRectobj = msgSurfaceObj.get_rect() 183 | if top == 0: 184 | pygame.draw.rect(windowSurfaceObj,bColor,Rect(bx+1,by+10,bw-4,int(bh/2.8))) 185 | msgRectobj.topleft = (bx + 5, by + 8) 186 | elif msg == "Timelapse" or msg == "Config": 187 | pygame.draw.rect(windowSurfaceObj,bColor,Rect(bx+2,by+int(bh/1.8),int(bw/2),int(bh/2.2)-1)) 188 | msgRectobj.topleft = (bx+10, by + int(bh/1.8)) 189 | elif top == 1: 190 | pygame.draw.rect(windowSurfaceObj,bColor,Rect(bx+20,by+int(bh/1.8),int(bw-21),int(bh/2.2)-1)) 191 | msgRectobj.topleft = (bx + 20, by + int(bh/1.8)) 192 | elif top == 2: 193 | if bkgnd_Color == 1: 194 | pygame.draw.rect(windowSurfaceObj,(0,0,0),Rect(0,0,preview_width,fv*2)) 195 | msgRectobj.topleft = (0,row * fsize) 196 | 197 | windowSurfaceObj.blit(msgSurfaceObj, msgRectobj) 198 | if upd == 1 and top == 2: 199 | pygame.display.update(0,0,preview_width,fv*2) 200 | if upd == 1: 201 | pygame.display.update(bx, by, bw, bh) 202 | 203 | def draw_bar(col,row,color,msg,value): 204 | global bw,bh,preview_width,still_limits,max_speed 205 | for f in range(0,len(still_limits)-1,3): 206 | if still_limits[f] == msg: 207 | pmin = still_limits[f+1] 208 | pmax = still_limits[f+2] 209 | if msg == "speed": 210 | pmax = max_speed 211 | pygame.draw.rect(windowSurfaceObj,color,Rect(preview_width + col*bw,row * bh,bw-1,10)) 212 | if pmin > -1: 213 | j = value / (pmax - pmin) * bw 214 | else: 215 | j = int(bw/2) + (value / (pmax - pmin) * bw) 216 | j = min(j,bw-5) 217 | pygame.draw.rect(windowSurfaceObj,(0,200,0),Rect(preview_width + (col*bw) + 2,row * bh,j+1,10)) 218 | pygame.draw.rect(windowSurfaceObj,(155,0,150),Rect(preview_width + (col*bw) + j ,row * bh,4,10)) 219 | pygame.display.update() 220 | 221 | def draw_Vbar(col,row,color,msg,value): 222 | global bw,bh,preview_width,video_limits 223 | for f in range(0,len(video_limits)-1,3): 224 | if video_limits[f] == msg: 225 | pmin = video_limits[f+1] 226 | pmax = video_limits[f+2] 227 | pygame.draw.rect(windowSurfaceObj,color,Rect(preview_width + col*bw,row * bh,bw-1,10)) 228 | if pmin > -1: 229 | j = value / (pmax - pmin) * bw 230 | else: 231 | j = int(bw/2) + (value / (pmax - pmin) * bw) 232 | j = min(j,bw-5) 233 | pygame.draw.rect(windowSurfaceObj,(150,120,150),Rect(preview_width + (col*bw) + 2,row * bh,j+1,10)) 234 | pygame.draw.rect(windowSurfaceObj,(155,0,150),Rect(preview_width + (col*bw) + j ,row * bh,4,10)) 235 | pygame.display.update() 236 | 237 | def preview(): 238 | global p, brightness,contrast,modes,mode,red,blue,ISO,sspeed,ev,preview_width,preview_height,zoom,igw,igh,zx,zy,awbs,awb,effects,effect,meters,meter,flickers,flicker,drcs,drc 239 | speed2 = sspeed 240 | if speed2 > 6000000: 241 | speed2 = 6000000 242 | rpistr = "raspistill -w " + str(preview_width) + " -h " + str(preview_height) + " -o /run/shm/test.jpg -co " + str(contrast) + " -br " + str(brightness) 243 | if modes[mode] == 'fixedfps': 244 | rpistr += " -t 0 -tl 0 -ex " + modes[mode] 245 | elif modes[mode] == 'off' : 246 | rpistr += " -t 0 -tl 0 -ex off -ss " + str(speed2) 247 | else: 248 | rpistr += " -t 0 -tl 0 -ex " + modes[mode] 249 | if ISO > 0: 250 | rpistr += " -ISO " + str(ISO) 251 | if ev != 0: 252 | rpistr += " -ev " + str(ev) 253 | rpistr += " -n" 254 | if awb == 0: 255 | rpistr += " -awb off -awbg " + str(red) + "," + str(blue) 256 | else: 257 | rpistr += " -awb " + awbs[awb] 258 | if effect > 0: 259 | rpistr += " -ifx " + effects[effect] 260 | if meter > 0: 261 | rpistr += " -mm " + meters[meter] 262 | if flicker > 0: 263 | rpistr += " -fli " + flickers[flicker] 264 | if drc > 0: 265 | rpistr += " -drc " + drcs[drc] 266 | if speed2 > 1000000 and modes[mode] == 'off': 267 | rpistr += " -bm" 268 | if zoom > 0 and zoom < 10: 269 | zwidth = preview_width * (5-zoom) 270 | if zwidth > igw: 271 | zwidth = igw - int(igw/20) 272 | zheight = preview_height * (5-zoom) 273 | if zheight > igh: 274 | zheight = igh - int(igh/20) 275 | zxo = ((igw-zwidth)/2)/igw 276 | zyo = ((igh-zheight)/2)/igh 277 | rpistr += " -roi " + str(zxo) + "," + str(zyo) + "," + str(zwidth/igw) + "," + str(zheight/igh) 278 | if zoom == 10: 279 | zxo = ((zx -((preview_width/2) / (igw/preview_width)))/preview_width) 280 | zyo = ((zy -((preview_height/2) / (igh/preview_height)))/preview_height) 281 | rpistr += " -roi " + str(zxo) + "," + str(zyo) + "," + str(preview_width/igw) + "," + str(preview_height/igh) 282 | #print (rpistr) 283 | p = subprocess.Popen(rpistr, shell=True, preexec_fn=os.setsid) 284 | 285 | # draw buttons 286 | for d in range(1,13): 287 | button(0,d,6,4) 288 | for d in range(1,5): 289 | button(1,d,7,3) 290 | for d in range(7,10): 291 | button(1,d,8,2) 292 | button(0,0,0,4) 293 | button(1,0,0,3) 294 | button(1,5,0,6) 295 | button(1,6,0,6) 296 | button(1,6,0,2) 297 | button(1,10,6,4) 298 | button(1,11,6,4) 299 | button(1,12,0,5) 300 | 301 | 302 | # write button texts 303 | text(0,0,1,0,1,"CAPTURE",ft,7) 304 | text(0,0,1,1,1,"Still",ft,7) 305 | text(1,0,1,0,1,"CAPTURE",ft,7) 306 | text(1,0,1,1,1,"Video",ft,7) 307 | text(0,1,5,0,1,"Mode",ft,10) 308 | text(0,1,3,1,1,modes[mode],fv,10) 309 | text(0,2,5,0,1,"Shutter S",ft,10) 310 | if mode == 0: 311 | if shutters[speed] < 0: 312 | text(0,2,3,1,1,"1/" + str(abs(shutters[speed])),fv,10) 313 | else: 314 | text(0,2,3,1,1,str(shutters[speed]),fv,10) 315 | else: 316 | if shutters[speed] < 0: 317 | text(0,2,0,1,1,"1/" + str(abs(shutters[speed])),fv,10) 318 | else: 319 | text(0,2,0,1,1,str(shutters[speed]),fv,10) 320 | text(0,3,5,0,1,"ISO",ft,10) 321 | if ISO != 0: 322 | text(0,3,3,1,1,str(ISO),fv,10) 323 | else: 324 | text(0,3,3,1,1,"Auto",fv,10) 325 | text(0,4,5,0,1,"Brightness",ft,10) 326 | text(0,4,3,1,1,str(brightness),fv,10) 327 | text(0,5,5,0,1,"Contrast",ft,10) 328 | text(0,5,3,1,1,str(contrast),fv,10) 329 | text(0,8,5,0,1,"Red",ft,10) 330 | if awb == 0: 331 | text(0,8,3,1,1,str(red)[0:3],fv,10) 332 | text(0,7,3,1,1,str(blue)[0:3],fv,10) 333 | else: 334 | text(0,8,0,1,1,str(red)[0:3],fv,10) 335 | text(0,7,0,1,1,str(blue)[0:3],fv,10) 336 | text(0,7,5,0,1,"Blue",ft,10) 337 | text(0,9,5,0,1,"File Format",ft,10) 338 | text(0,9,3,1,1,extns[extn],fv,10) 339 | if zoom == 0: 340 | button(1,5,0,4) 341 | text(1,5,5,0,1,"Focus / Zoom",ft,7) 342 | text(1,5,3,1,1,"",fv,7) 343 | text(1,3,3,1,1,str(vwidth) + "x" + str(vheight),fv,11) 344 | elif zoom < 10: 345 | button(1,5,1,4) 346 | text(1,5,2,0,1,"ZOOMED",ft,0) 347 | text(1,5,3,1,1,str(zoom),fv,0) 348 | text(1,3,3,1,1,str(preview_width) + "x" + str(preview_height),fv,11) 349 | else: 350 | button(1,5,0,4) 351 | text(1,5,3,0,1,"FOCUS",ft,0) 352 | text(1,3,3,1,1,str(vwidth) + "x" + str(vheight),fv,11) 353 | 354 | text(0,6,5,0,1,"eV",ft,10) 355 | if mode != 0: 356 | text(0,6,3,1,1,str(ev),fv,10) 357 | else: 358 | text(0,6,0,1,1,str(ev),fv,10) 359 | text(1,1,5,0,1,"V_Length S",ft,11) 360 | text(1,2,5,0,1,"V_FPS",ft,11) 361 | text(1,2,3,1,1,str(fps),fv,11) 362 | text(1,1,3,1,1,str(vlen),fv,11) 363 | text(1,3,5,0,1,"V_Format",ft,11) 364 | text(0,10,5,0,1,"AWB",ft,10) 365 | text(0,10,3,1,1,awbs[awb],fv,10) 366 | text(1,4,5,0,1,"V_Annotate",ft,11) 367 | if a_video == 0: 368 | text(1,4,3,1,1,"OFF",fv,11) 369 | elif a_video == 1: 370 | text(1,4,3,1,1,"ON 1",fv,11) 371 | else: 372 | text(1,4,3,1,1,"ON 2",fv,11) 373 | text(1,6,1,0,1,"CAPTURE",ft,7) 374 | text(1,6,1,1,1,"Timelapse",ft,7) 375 | text(1,7,5,0,1,"Duration S",ft,12) 376 | text(1,7,3,1,1,str(tduration),fv,12) 377 | text(1,8,5,0,1,"Interval S",ft,12) 378 | text(1,8,3,1,1,str(tinterval),fv,12) 379 | text(1,9,5,0,1,"No. of Shots",ft,12) 380 | text(1,9,3,1,1,str(tshots),fv,12) 381 | text(0,11,5,0,1,"Effects",fv,10) 382 | text(0,11,3,1,1,effects[effect],fv,10) 383 | text(0,12,5,0,1,"Metering",fv,10) 384 | text(0,12,3,1,1,meters[meter],fv,10) 385 | text(1,10,5,0,1,"DRC",fv,10) 386 | text(1,10,3,1,1,drcs[drc],fv,10) 387 | text(1,11,5,0,1,"Flicker",fv,10) 388 | text(1,11,3,1,1,flickers[flicker],fv,10) 389 | text(1,12,2,0,1,"Save EXIT",fv,7) 390 | text(1,12,2,1,1,"Config",fv,7) 391 | 392 | # draw sliders 393 | draw_bar(0,3,lgrnColor,'ISO',ISO) 394 | draw_bar(0,4,lgrnColor,'brightness',brightness) 395 | draw_bar(0,5,lgrnColor,'contrast',contrast) 396 | draw_bar(0,6,lgrnColor,'ev',ev) 397 | draw_bar(0,7,lgrnColor,'blue',blue) 398 | draw_bar(0,8,lgrnColor,'red',red) 399 | draw_Vbar(1,1,lpurColor,'vlen',vlen) 400 | draw_Vbar(1,2,lpurColor,'fps',fps) 401 | draw_Vbar(1,7,lyelColor,'tduration',tduration) 402 | draw_Vbar(1,8,lyelColor,'tinterval',tinterval) 403 | draw_Vbar(1,9,lyelColor,'tshots',tshots) 404 | 405 | text(0,0,6,2,1,"Please Wait, checking camera",int(fv* 1.7),1) 406 | pygame.display.update() 407 | 408 | # Check for Pi Camera version 409 | if os.path.exists('test.jpg'): 410 | os.rename('test.jpg', 'oldtest.jpg') 411 | rpistr = "raspistill -n -o test.jpg -t 100" 412 | os.system(rpistr) 413 | time.sleep(2) 414 | if os.path.exists('test.jpg'): 415 | imagefile = 'test.jpg' 416 | image = pygame.image.load(imagefile) 417 | igw = image.get_width() 418 | igh = image.get_height() 419 | if igw == 2592: 420 | Pi_Cam = 1 421 | max_shutter = 6 422 | elif igw == 3280: 423 | Pi_Cam = 2 424 | max_shutter = 10 425 | else: 426 | Pi_Cam = 3 427 | max_shutter = 239 428 | else: 429 | Pi_Cam = 0 430 | max_shutter = 6 431 | 432 | # determine max speed for camera 433 | max_speed = 0 434 | while max_shutter > shutters[max_speed]: 435 | max_speed +=1 436 | 437 | if Pi_Cam > 0: 438 | text(0,0,6,2,1,"Found Pi Camera v" + str(Pi_Cam),int(fv*1.7),1) 439 | else: 440 | text(0,0,6,2,1,"No Pi Camera found",int(fv*1.7),1) 441 | 442 | # set maximum speed, based on camera version 443 | if speed > max_speed: 444 | speed = max_speed 445 | shutter = shutters[speed] 446 | if shutter < 0: 447 | shutter = abs(1/shutter) 448 | sspeed = int(shutter * 1000000) 449 | if mode == 0: 450 | if shutters[speed] < 0: 451 | text(0,2,3,1,1,"1/" + str(abs(shutters[speed])),fv,10) 452 | else: 453 | text(0,2,3,1,1,str(shutters[speed]),fv,10) 454 | else: 455 | if shutters[speed] < 0: 456 | text(0,2,0,1,1,"1/" + str(abs(shutters[speed])),fv,10) 457 | else: 458 | text(0,2,0,1,1,str(shutters[speed]),fv,10) 459 | 460 | draw_bar(0,2,lgrnColor,'speed',speed) 461 | pygame.display.update() 462 | time.sleep(.25) 463 | text(0,0,6,2,1,"Please Wait for preview...",int(fv*1.7),1) 464 | 465 | # start preview 466 | preview() 467 | 468 | # main loop 469 | while True: 470 | time.sleep(0.01) 471 | # load preview image 472 | if os.path.exists('/run/shm/test.jpg'): 473 | image = pygame.image.load('/run/shm/test.jpg') 474 | os.rename('/run/shm/test.jpg', '/run/shm/oldtest.jpg') 475 | windowSurfaceObj.blit(image, (0, 0)) 476 | if zoom > 0: 477 | image2 = pygame.surfarray.pixels3d(image) 478 | crop2 = image2[zx-50:zx+50,zy-50:zy+50] 479 | gray = cv2.cvtColor(crop2,cv2.COLOR_RGB2GRAY) 480 | foc = cv2.Laplacian(gray, cv2.CV_64F).var() 481 | text(20,0,3,2,0,"Focus: " + str(int(foc)),fv* 2,0) 482 | xx = int(preview_width/2) 483 | xy = int(preview_height/2) 484 | pygame.draw.line(windowSurfaceObj,redColor,(xx-25,xy),(xx+25,xy),1) 485 | pygame.draw.line(windowSurfaceObj,redColor,(xx,xy-25),(xx,xy+25),1) 486 | else: 487 | text(0,0,6,2,0,"Preview",fv* 2,0) 488 | zxp = (zx -((preview_width/2) / (igw/preview_width))) 489 | zyp = (zy -((preview_height/2) / (igh/preview_height))) 490 | zxq = (zx - zxp) * 2 491 | zyq = (zy - zyp) * 2 492 | if zxp + zxq > preview_width: 493 | zx = preview_width - int(zxq/2) 494 | zxp = (zx -((preview_width/2) / (igw/preview_width))) 495 | zxq = (zx - zxp) * 2 496 | if zyp + zyq > preview_height: 497 | zy = preview_height - int(zyq/2) 498 | zyp = (zy -((preview_height/2) / (igh/preview_height))) 499 | zyq = (zy - zyp) * 2 500 | if zxp < 0: 501 | zx = int(zxq/2) + 1 502 | zxp = 0 503 | zxq = (zx - zxp) * 2 504 | if zyp < 0: 505 | zy = int(zyq/2) + 1 506 | zyp = 0 507 | zyq = (zy - zyp) * 2 508 | if zoom == 0: 509 | pygame.draw.rect(windowSurfaceObj,redColor,Rect(zxp,zyp,zxq,zyq),1) 510 | pygame.draw.line(windowSurfaceObj,redColor,(zx-25,zy),(zx+25,zy),1) 511 | pygame.draw.line(windowSurfaceObj,redColor,(zx,zy-25),(zx,zy+25),1) 512 | if vwidth == 1920 and vheight == 1080: 513 | pygame.draw.rect(windowSurfaceObj,(155,0,150),Rect(preview_width * 0.13,preview_height * 0.22,preview_width * 0.74,preview_height * 0.57),1) 514 | if vwidth == 1280 and vheight == 720: 515 | pygame.draw.rect(windowSurfaceObj,(155,0,150),Rect(0,0,preview_width,preview_height*.75),1) 516 | pygame.display.update() 517 | restart = 0 518 | # continuously read mouse buttons 519 | buttonx = pygame.mouse.get_pressed() 520 | if buttonx[0] != 0 : 521 | time.sleep(0.1) 522 | pos = pygame.mouse.get_pos() 523 | mousex = pos[0] 524 | mousey = pos[1] 525 | if mousex > preview_width: 526 | button_column = int((mousex-preview_width)/bw) + 1 527 | button_row = int((mousey)/bh) + 1 528 | if button_column == 1: 529 | if button_row == 2: 530 | for f in range(0,len(still_limits)-1,3): 531 | if still_limits[f] == 'mode': 532 | pmin = still_limits[f+1] 533 | pmax = still_limits[f+2] 534 | if mousex > preview_width + (bw/2): 535 | mode +=1 536 | mode = min(mode,pmax) 537 | else: 538 | mode -=1 539 | mode = max(mode,pmin) 540 | if mode != 0: 541 | text(0,6,3,1,1,str(ev),fv,10) 542 | else: 543 | text(0,6,0,1,1,str(ev),fv,10) 544 | if mode == 0: 545 | if shutters[speed] < 0: 546 | text(0,2,3,1,1,"1/" + str(abs(shutters[speed])),fv,10) 547 | else: 548 | text(0,2,3,1,1,str(shutters[speed]),fv,10) 549 | else: 550 | if shutters[speed] < 0: 551 | text(0,2,0,1,1,"1/" + str(abs(shutters[speed])),fv,10) 552 | else: 553 | text(0,2,0,1,1,str(shutters[speed]),fv,10) 554 | text(0,1,3,1,1,modes[mode],fv,10) 555 | draw_bar(0,2,lgrnColor,'speed',speed) 556 | if mode == 0 and sspeed < 6000001: 557 | tinterval = max(tinterval,int((sspeed/1000000) * 6.33)) 558 | if mode == 0 and sspeed > 6000000: 559 | tinterval = max(tinterval,int((sspeed/1000000))) 560 | text(1,8,3,1,1,str(tinterval),fv,12) 561 | draw_Vbar(1,9,lyelColor,'tinterval',tinterval) 562 | tduration = tinterval * tshots 563 | text(1,7,3,1,1,str(tduration),fv,12) 564 | draw_Vbar(1,8,lyelColor,'tduration',tduration) 565 | time.sleep(.25) 566 | restart = 1 567 | 568 | elif button_row == 3: 569 | if mode == 0 : 570 | for f in range(0,len(still_limits)-1,3): 571 | if still_limits[f] == 'speed': 572 | pmin = still_limits[f+1] 573 | pmax = still_limits[f+2] 574 | if mousey < ((button_row-1)*bh) + 10: 575 | speed = int(((mousex-preview_width) / bw) * (max_speed-pmin)) 576 | shutter = shutters[speed] 577 | if shutter < 0: 578 | shutter = abs(1/shutter) 579 | sspeed = int(shutter * 1000000) 580 | elif mousey < ((button_row-1)*bh) + (bh/1.2): 581 | if mousex > preview_width + (bw/2): 582 | speed +=1 583 | speed = min(speed,max_speed) 584 | else: 585 | speed -=1 586 | speed = max(pmin,speed) 587 | shutter = shutters[speed] 588 | if shutter < 0: 589 | shutter = abs(1/shutter) 590 | sspeed = int(shutter * 1000000) 591 | if (shutter * 1000000) - int(shutter * 1000000) > 0.5: 592 | sspeed +=1 593 | 594 | if shutters[speed] < 0: 595 | text(0,2,3,1,1,"1/" + str(abs(shutters[speed])),fv,10) 596 | else: 597 | text(0,2,3,1,1,str(shutters[speed]),fv,10) 598 | draw_bar(0,2,lgrnColor,'speed',speed) 599 | if mode == 0 and sspeed < 6000001: 600 | tinterval = max(tinterval,int((sspeed/1000000) * 6.33)) 601 | if mode == 0 and sspeed > 6000000: 602 | tinterval = max(tinterval,int((sspeed/1000000))) 603 | text(1,8,3,1,1,str(tinterval),fv,12) 604 | draw_Vbar(1,9,lyelColor,'tinterval',tinterval) 605 | tduration = tinterval * tshots 606 | text(1,7,3,1,1,str(tduration),fv,12) 607 | draw_Vbar(1,8,lyelColor,'tduration',tduration) 608 | time.sleep(.25) 609 | restart = 1 610 | 611 | elif button_row == 4: 612 | for f in range(0,len(still_limits)-1,3): 613 | if still_limits[f] == 'ISO': 614 | pmin = still_limits[f+1] 615 | pmax = still_limits[f+2] 616 | if mousey < ((button_row-1)*bh) + 10: 617 | ISO = int(((mousex-preview_width) / bw) * (pmax-pmin)) 618 | if ISO < 100: 619 | ISO = 0 620 | elif ISO < 200: 621 | ISO = 100 622 | elif ISO < 400: 623 | ISO = 200 624 | elif ISO < 700: 625 | ISO = 400 626 | else: 627 | ISO = 800 628 | elif mousey < ((button_row-1)*bh) + (bh/1.2): 629 | if mousex < preview_width + (bw/2): 630 | if ISO == 100: 631 | ISO -=100 632 | else: 633 | ISO = int(ISO / 2) 634 | ISO = max(ISO,pmin) 635 | else: 636 | if ISO == 0: 637 | ISO +=100 638 | else: 639 | ISO = ISO * 2 640 | ISO = min(ISO,pmax) 641 | if ISO != 0: 642 | text(0,3,3,1,1,str(ISO),fv,10) 643 | else: 644 | text(0,3,3,1,1,"Auto",fv,10) 645 | time.sleep(.25) 646 | draw_bar(0,3,lgrnColor,'ISO',ISO) 647 | restart = 1 648 | 649 | elif button_row == 5: 650 | for f in range(0,len(still_limits)-1,3): 651 | if still_limits[f] == 'brightness': 652 | pmin = still_limits[f+1] 653 | pmax = still_limits[f+2] 654 | if mousey < ((button_row-1)*bh) + 10: 655 | brightness = int(((mousex-preview_width) / bw) * (pmax-pmin)) 656 | elif mousey < ((button_row-1)*bh) + (bh/1.2): 657 | if mousex > preview_width + (bw/2): 658 | brightness +=1 659 | brightness = min(brightness,pmax) 660 | else: 661 | brightness -=1 662 | brightness = max(brightness,pmin) 663 | text(0,4,3,1,1,str(brightness),fv,10) 664 | draw_bar(0,4,lgrnColor,'brightness',brightness) 665 | restart = 1 666 | 667 | elif button_row == 6: 668 | for f in range(0,len(still_limits)-1,3): 669 | if still_limits[f] == 'contrast': 670 | pmin = still_limits[f+1] 671 | pmax = still_limits[f+2] 672 | if mousey < ((button_row-1)*bh) + 10: 673 | contrast = int(((mousex-preview_width) / bw) * (pmax-pmin)) - 100 674 | elif mousey < ((button_row-1)*bh) + (bh/1.2): 675 | if mousex > preview_width + (bw/2): 676 | contrast +=1 677 | contrast = min(contrast,pmax) 678 | else: 679 | contrast -=1 680 | contrast = max(contrast,pmin) 681 | text(0,5,3,1,1,str(contrast),fv,10) 682 | draw_bar(0,5,lgrnColor,'contrast',contrast) 683 | restart = 1 684 | 685 | elif button_row == 7 and mode != 0: 686 | for f in range(0,len(still_limits)-1,3): 687 | if still_limits[f] == 'ev': 688 | pmin = still_limits[f+1] 689 | pmax = still_limits[f+2] 690 | if mousey < ((button_row-1)*bh) + 10: 691 | ev = int(((mousex-preview_width) / bw) * (pmax-pmin)) - 12 692 | elif mousey < ((button_row-1)*bh) + (bh/1.2): 693 | if mousex > preview_width + (bw/2): 694 | ev +=1 695 | ev = min(ev,pmax) 696 | else: 697 | ev -=1 698 | ev = max(ev,pmin) 699 | text(0,6,3,1,1,str(ev),fv,10) 700 | draw_bar(0,6,lgrnColor,'ev',ev) 701 | restart = 1 702 | 703 | elif button_row == 8 and awb == 0: 704 | for f in range(0,len(still_limits)-1,3): 705 | if still_limits[f] == 'blue': 706 | pmin = still_limits[f+1] 707 | pmax = still_limits[f+2] 708 | if mousey < ((button_row-1)*bh) + 10: 709 | blue = (((mousex-preview_width) / bw) * (pmax-pmin)) 710 | elif mousey < ((button_row-1)*bh) + (bh/1.2): 711 | if mousex < preview_width + (bw/2): 712 | blue -=0.1 713 | blue = max(blue,pmin) 714 | else: 715 | blue +=0.1 716 | blue = min(blue,pmax) 717 | text(0,7,3,1,1,str(blue)[0:3],fv,10) 718 | draw_bar(0,7,lgrnColor,'blue',blue) 719 | time.sleep(.25) 720 | restart = 1 721 | 722 | elif button_row == 9 and awb == 0 : 723 | for f in range(0,len(still_limits)-1,3): 724 | if still_limits[f] == 'red': 725 | pmin = still_limits[f+1] 726 | pmax = still_limits[f+2] 727 | if mousey < ((button_row-1)*bh) + 10: 728 | red = (((mousex-preview_width) / bw) * (pmax-pmin)) 729 | elif mousey < ((button_row-1)*bh) + (bh/1.2): 730 | if mousex < preview_width + (bw/2): 731 | red -=0.1 732 | red = max(red,pmin) 733 | else: 734 | red +=0.1 735 | red = min(red,pmax) 736 | text(0,8,3,1,1,str(red)[0:3],fv,10) 737 | draw_bar(0,8,lgrnColor,'red',red) 738 | time.sleep(.25) 739 | restart = 1 740 | 741 | elif button_row == 10: 742 | for f in range(0,len(still_limits)-1,3): 743 | if still_limits[f] == 'extn': 744 | pmin = still_limits[f+1] 745 | pmax = still_limits[f+2] 746 | if mousex < preview_width + (bw/2): 747 | extn -=1 748 | extn = max(extn,pmin) 749 | else: 750 | extn +=1 751 | extn = min(extn,pmax) 752 | text(0,9,3,1,1,extns[extn],fv,10) 753 | time.sleep(.25) 754 | 755 | elif button_row == 11: 756 | for f in range(0,len(still_limits)-1,3): 757 | if still_limits[f] == 'awb': 758 | pmin = still_limits[f+1] 759 | pmax = still_limits[f+2] 760 | if mousex > preview_width + (bw/2): 761 | awb +=1 762 | awb = min(awb,pmax) 763 | else: 764 | awb -=1 765 | awb = max(awb,pmin) 766 | text(0,10,3,1,1,awbs[awb],fv,10) 767 | if awb == 0: 768 | text(0,8,3,1,1,str(red)[0:3],fv,10) 769 | text(0,7,3,1,1,str(blue)[0:3],fv,10) 770 | else: 771 | text(0,8,0,1,1,str(red)[0:3],fv,10) 772 | text(0,7,0,1,1,str(blue)[0:3],fv,10) 773 | time.sleep(.25) 774 | restart = 1 775 | 776 | elif button_row == 12: 777 | for f in range(0,len(still_limits)-1,3): 778 | if still_limits[f] == 'effect': 779 | pmin = still_limits[f+1] 780 | pmax = still_limits[f+2] 781 | if mousex > preview_width + (bw/2): 782 | effect +=1 783 | effect = min(effect,pmax) 784 | else: 785 | effect -=1 786 | effect = max(effect,pmin) 787 | text(0,11,3,1,1,effects[effect],fv,10) 788 | time.sleep(.25) 789 | restart = 1 790 | 791 | elif button_row == 13: 792 | for f in range(0,len(still_limits)-1,3): 793 | if still_limits[f] == 'meter': 794 | pmin = still_limits[f+1] 795 | pmax = still_limits[f+2] 796 | if mousex > preview_width + (bw/2): 797 | meter +=1 798 | meter = min(meter,pmax) 799 | else: 800 | meter -=1 801 | meter = max(meter,pmin) 802 | text(0,12,3,1,1,meters[meter],fv,10) 803 | time.sleep(.25) 804 | restart = 1 805 | 806 | elif button_column == 2: 807 | if button_row == 2: 808 | for f in range(0,len(video_limits)-1,3): 809 | if video_limits[f] == 'vlen': 810 | pmin = video_limits[f+1] 811 | pmax = video_limits[f+2] 812 | if mousey < ((button_row-1)*bh) + 10: 813 | vlen = int(((mousex-preview_width - bw) / bw) * (pmax-pmin)) 814 | elif mousey < ((button_row-1)*bh) + (bh/1.2): 815 | if mousex > preview_width + bw + (bw/2): 816 | vlen +=1 817 | vlen = min(vlen,pmax) 818 | else: 819 | vlen -=1 820 | vlen = max(vlen,pmin) 821 | vlen = min(vlen,video_limits[2]) 822 | text(1,1,3,1,1,str(vlen),fv,11) 823 | draw_Vbar(1,1,lpurColor,'vlen',vlen) 824 | #restart = 1 825 | time.sleep(.25) 826 | 827 | elif button_row == 3: 828 | for f in range(0,len(video_limits)-1,3): 829 | if video_limits[f] == 'fps': 830 | pmin = video_limits[f+1] 831 | pmax = video_limits[f+2] 832 | if mousey < ((button_row-1)*bh) + 10: 833 | fps = int(((mousex-preview_width-bw) / bw) * (pmax-pmin)) 834 | fps = min(fps,vfps) 835 | fps = max(fps,pmin) 836 | elif mousey < ((button_row-1)*bh) + (bh/1.2): 837 | if mousex > preview_width + bw + (bw/2): 838 | fps +=1 839 | fps = min(fps,vfps) 840 | else: 841 | fps -=1 842 | fps = max(fps,video_limits[4]) 843 | text(1,2,3,1,1,str(fps),fv,11) 844 | draw_Vbar(1,2,lpurColor,'fps',fps) 845 | time.sleep(.25) 846 | 847 | elif button_row == 4 and zoom == 0: 848 | for f in range(0,len(video_limits)-1,3): 849 | if video_limits[f] == 'vformat': 850 | pmin = video_limits[f+1] 851 | pmax = video_limits[f+2] 852 | if mousex < preview_width + bw + (bw/2): 853 | vformat -=1 854 | vformat = max(vformat,pmin) 855 | else: 856 | vformat +=1 857 | vformat = min(vformat,pmax) 858 | vwidth = vwidths[vformat] 859 | vheight = vheights[vformat] 860 | vfps = v_max_fps[vformat] 861 | fps = min(fps,vfps) 862 | video_limits[5] = vfps 863 | text(1,2,3,1,1,str(fps),fv,11) 864 | draw_Vbar(1,2,lpurColor,'fps',fps) 865 | text(1,3,3,1,1,str(vwidth) + "x" + str(vheight),fv,11) 866 | time.sleep(.25) 867 | 868 | elif button_row == 5: 869 | a_video +=1 870 | if a_video > 2: 871 | a_video = 0 872 | if a_video == 0: 873 | text(1,4,3,1,1,"OFF",fv,11) 874 | elif a_video == 1: 875 | text(1,4,3,1,1,"ON 1",fv,11) 876 | else: 877 | text(1,4,3,1,1,"ON 2",fv,11) 878 | time.sleep(.5) 879 | 880 | elif button_row == 6: 881 | for f in range(0,len(video_limits)-1,3): 882 | if video_limits[f] == 'zoom': 883 | pmin = video_limits[f+1] 884 | pmax = video_limits[f+2] 885 | if mousex > preview_width + bw + (bw/2) and zoom == 0: 886 | zoom +=1 887 | zoom = min(zoom,pmax) 888 | button(1,5,1,4) 889 | text(1,5,2,0,1,"ZOOMED",ft,0) 890 | text(1,5,3,1,1,str(zoom),fv,0) 891 | text(1,3,3,1,1,str(preview_width) + "x" + str(preview_height),fv,11) 892 | elif mousex > preview_width + bw + (bw/2) and zoom > 0 and zoom != 10: 893 | zoom +=1 894 | zoom = min(zoom,pmax) 895 | button(1,5,1,4) 896 | text(1,5,2,0,1,"ZOOMED",ft,0) 897 | text(1,5,3,1,1,str(zoom),fv,0) 898 | text(1,3,3,1,1,str(preview_width) + "x" + str(preview_height),fv,11) 899 | elif mousex < preview_width + bw + (bw/2) and zoom > 0 and zoom < 10: 900 | zoom -=1 901 | if zoom == 0: 902 | button(1,5,0,4) 903 | text(1,5,5,0,1,"Focus / Zoom",ft,7) 904 | text(1,5,3,1,1,"",fv,7) 905 | text(1,3,3,1,1,str(vwidth) + "x" + str(vheight),fv,11) 906 | else: 907 | button(1,5,1,4) 908 | text(1,5,2,0,1,"ZOOMED",ft,0) 909 | text(1,5,3,1,1,str(zoom),fv,0) 910 | text(1,3,3,1,1,str(preview_width) + "x" + str(preview_height),fv,11) 911 | elif mousex < preview_width + bw + (bw/2) and zoom == 0: 912 | zoom = 10 913 | button(1,5,1,6) 914 | text(1,5,3,0,1,"FOCUS",ft,0) 915 | text(1,3,3,1,1,str(preview_width) + "x" + str(preview_height),fv,11) 916 | elif zoom == 10: 917 | zoom = 0 918 | button(1,5,0,4) 919 | text(1,5,5,0,1,"Zoom / Focus",ft,7) 920 | text(1,5,3,1,1,"",fv,7) 921 | text(1,3,3,1,1,str(vwidth) + "x" + str(vheight),fv,11) 922 | 923 | 924 | 925 | time.sleep(.25) 926 | restart = 1 927 | 928 | elif button_row == 8: 929 | for f in range(0,len(video_limits)-1,3): 930 | if video_limits[f] == 'tduration': 931 | pmin = video_limits[f+1] 932 | pmax = video_limits[f+2] 933 | if mousey < ((button_row-1)*bh) + 10: 934 | tduration = int(((mousex-preview_width - bw) / bw) * (pmax-pmin)) 935 | elif mousey < ((button_row-1)*bh) + (bh/1.2): 936 | if mousex > preview_width + bw + (bw/2): 937 | tduration +=1 938 | tduration = min(tduration,pmax) 939 | else: 940 | tduration -=1 941 | tduration = max(tduration,pmin) 942 | text(1,7,3,1,1,str(tduration),fv,12) 943 | draw_Vbar(1,7,lyelColor,'tduration',tduration) 944 | tshots = int(tduration / tinterval) 945 | text(1,9,3,1,1,str(tshots),fv,12) 946 | draw_Vbar(1,9,lyelColor,'tshots',tshots) 947 | time.sleep(.25) 948 | 949 | elif button_row == 9: 950 | for f in range(0,len(video_limits)-1,3): 951 | if video_limits[f] == 'tinterval': 952 | pmin = video_limits[f+1] 953 | pmax = video_limits[f+2] 954 | if mousey < ((button_row-1)*bh) + 10: 955 | tinterval = int(((mousex-preview_width-bw) / bw) * (pmax - pmin)) 956 | elif mousey < ((button_row-1)*bh) + (bh/1.2): 957 | if mousex > preview_width + bw + (bw/2): 958 | tinterval +=1 959 | tinterval = min(tinterval,pmax) 960 | if mode == 0 and sspeed < 6000001: 961 | tinterval = max(tinterval,int((sspeed/1000000) * 6.33)) 962 | if mode == 0 and sspeed > 6000000: 963 | tinterval = max(tinterval,int((sspeed/1000000))) 964 | else: 965 | tinterval -=1 966 | tinterval = max(tinterval,pmin) 967 | text(1,8,3,1,1,str(tinterval),fv,12) 968 | draw_Vbar(1,8,lyelColor,'tinterval',tinterval) 969 | tduration = tinterval * tshots 970 | text(1,7,3,1,1,str(tduration),fv,12) 971 | draw_Vbar(1,7,lyelColor,'tduration',tduration) 972 | time.sleep(.25) 973 | 974 | elif button_row == 10: 975 | for f in range(0,len(video_limits)-1,3): 976 | if video_limits[f] == 'tshots': 977 | pmin = video_limits[f+1] 978 | pmax = video_limits[f+2] 979 | if mousey < ((button_row-1)*bh) + 10: 980 | tshots = int(((mousex-preview_width-bw) / bw) * (pmax-pmin)) 981 | elif mousey < ((button_row-1)*bh) + (bh/1.2): 982 | if mousex > preview_width + bw + (bw/2): 983 | tshots +=1 984 | tshots = min(tshots,pmax) 985 | else: 986 | tshots -=1 987 | tshots = max(tshots,pmin) 988 | text(1,9,3,1,1,str(tshots),fv,12) 989 | draw_Vbar(1,9,lyelColor,'tshots',tshots) 990 | tduration = tinterval * tshots 991 | text(1,7,3,1,1,str(tduration),fv,12) 992 | draw_Vbar(1,7,lyelColor,'tduration',tduration) 993 | time.sleep(.25) 994 | 995 | elif button_row == 11: 996 | for f in range(0,len(video_limits)-1,3): 997 | if video_limits[f] == 'drc': 998 | pmin = video_limits[f+1] 999 | pmax = video_limits[f+2] 1000 | if mousex > preview_width + bw + (bw/2): 1001 | drc +=1 1002 | drc = min(drc,pmax) 1003 | else: 1004 | drc -=1 1005 | drc = max(drc,pmin) 1006 | text(1,10,3,1,1,drcs[drc],fv,10) 1007 | time.sleep(.25) 1008 | restart = 1 1009 | 1010 | elif button_row == 12: 1011 | for f in range(0,len(video_limits)-1,3): 1012 | if video_limits[f] == 'flicker': 1013 | pmin = video_limits[f+1] 1014 | pmax = video_limits[f+2] 1015 | if mousex > preview_width + bw + (bw/2): 1016 | flicker +=1 1017 | flicker = min(flicker,pmax) 1018 | else: 1019 | flicker -=1 1020 | flicker = max(flicker,pmin) 1021 | text(1,11,3,1,1,flickers[flicker],fv,10) 1022 | time.sleep(.25) 1023 | restart = 1 1024 | 1025 | 1026 | elif button_row == 13: 1027 | if mousex < preview_width + bw + (bw/2): 1028 | # save config 1029 | text(1,12,3,1,1,"Config",fv,7) 1030 | config[0] = mode 1031 | config[1] = speed 1032 | config[2] = ISO 1033 | config[3] = brightness 1034 | config[4] = contrast 1035 | config[5] = frame 1036 | config[6] = int(red*10) 1037 | config[7] = int(blue*10) 1038 | config[8] = ev 1039 | config[9] = vlen 1040 | config[10] = fps 1041 | config[11] = vformat 1042 | config[12] = a_video 1043 | config[13] = tinterval 1044 | config[14] = tshots 1045 | config[15] = tduration 1046 | config[16] = extn 1047 | config[17] = zx 1048 | config[18] = zy 1049 | config[19] = zoom 1050 | config[20] = effect 1051 | config[21] = meter 1052 | config[22] = awb 1053 | config[23] = flicker 1054 | config[24] = drc 1055 | with open(config_file, 'w') as f: 1056 | for item in config: 1057 | f.write("%s\n" % item) 1058 | time.sleep(1) 1059 | text(1,12,2,1,1,"Config",fv,7) 1060 | else: 1061 | os.killpg(p.pid, signal.SIGTERM) 1062 | pygame.display.quit() 1063 | sys.exit() 1064 | 1065 | if restart > 0: 1066 | if restart == 1: 1067 | os.killpg(p.pid, signal.SIGTERM) 1068 | text(0,0,6,2,1,"Waiting for preview ...",int(fv*1.7),1) 1069 | preview() 1070 | 1071 | #check for any mouse button presses 1072 | for event in pygame.event.get(): 1073 | if event.type == QUIT: 1074 | os.killpg(p.pid, signal.SIGTERM) 1075 | pygame.quit() 1076 | elif (event.type == MOUSEBUTTONUP): 1077 | restart = 0 1078 | mousex, mousey = event.pos 1079 | if mousex < preview_width and zoom == 0: 1080 | zx = mousex 1081 | zy = mousey 1082 | if mousex > preview_width: 1083 | button_column = int((mousex-preview_width)/bw) + 1 1084 | button_row = int((mousey)/bh) + 1 1085 | y = button_row-1 1086 | if button_column == 1: 1087 | if button_row == 1: 1088 | # still 1089 | os.killpg(p.pid, signal.SIGTERM) 1090 | button(0,0,1,4) 1091 | text(0,0,2,0,1,"CAPTURE",ft,0) 1092 | text(1,0,0,0,1,"CAPTURE",ft,7) 1093 | text(1,0,0,1,1,"Video",ft,7) 1094 | text(1,6,0,0,1,"CAPTURE",ft,7) 1095 | text(1,6,0,1,1,"Timelapse",ft,7) 1096 | text(0,0,6,2,1,"Please Wait, taking still ...",int(fv*1.7),1) 1097 | now = datetime.datetime.now() 1098 | timestamp = now.strftime("%y%m%d%H%M%S") 1099 | fname = pic_dir + str(timestamp) + '.' + extns[extn] 1100 | if speed < 6000001: 1101 | rpistr = "raspistill -o " + str(fname) + " -e " + extns[extn] + " -co " + str(contrast) + " -br " + str(brightness) 1102 | rpistr += " -awb off -awbg " + str(red) + "," + str(blue) 1103 | zwidth = preview_width * (5-zoom) 1104 | if zwidth > igw: 1105 | zwidth = igw - int(igw/20) 1106 | zheight = preview_height * (5-zoom) 1107 | if zheight > igh: 1108 | zheight = igh - int(igh/20) 1109 | if zoom == 10: 1110 | rpistr += " -w " + str(preview_width) + " -h " + str(preview_height) 1111 | elif zoom > 0 and zoom < 10: 1112 | rpistr += " -w " + str(zwidth) + " -h " + str(zheight) 1113 | if modes[mode] != 'off': 1114 | rpistr += " -t 800 -ex " + modes[mode] 1115 | else: 1116 | rpistr += " -t 500 -ex off -ss " + str(sspeed) 1117 | if ISO > 0 and modes[mode] != 'off': 1118 | rpistr += " -ISO " + str(ISO) 1119 | if ev != 0 and modes[mode] != 'off': 1120 | rpistr += " -ev " + str(ev) 1121 | else: 1122 | rpistr = "raspistill -t 10 -md 3 -bm -ex off -ag 1 -ss " + str(sspeed) + " -st -o " + fname + " -e " + extns[extn] 1123 | zwidth = preview_width * (5-zoom) 1124 | zheight = preview_height * (5-zoom) 1125 | if zoom == 10: 1126 | rpistr += " -w " + str(preview_width) + " -h " + str(preview_height) 1127 | elif zoom > 0 and zoom < 10: 1128 | rpistr += " -w " + str(zwidth) + " -h " + str(zheight) 1129 | rpistr += " -co " + str(contrast) + " -br " + str(brightness) 1130 | rpistr += " -awb off -awbg " + str(red) + "," + str(blue) 1131 | rpistr += " -n " 1132 | if awb == 0: 1133 | rpistr += " -awb off -awbg " + str(red) + "," + str(blue) 1134 | else: 1135 | rpistr += " -awb " + awbs[awb] 1136 | if effect > 0: 1137 | rpistr += " -ifx " + effects[effect] 1138 | if meter > 0: 1139 | rpistr += " -mm " + meters[meter] 1140 | if flicker > 0: 1141 | rpistr += " -fli " + flickers[flicker] 1142 | if drc > 0: 1143 | rpistr += " -drc " + drcs[drc] 1144 | if zoom > 0 and zoom < 10: 1145 | zwidth = preview_width * (5-zoom) 1146 | if zwidth > igw: 1147 | zwidth = igw - int(igw/20) 1148 | zheight = preview_height * (5-zoom) 1149 | if zheight > igh: 1150 | zheight = igh - int(igh/20) 1151 | rpistr += " -w " + str(zwidth) + " -h " + str(zheight) 1152 | zxo = ((igw-zwidth)/2)/igw 1153 | zyo = ((igh-zheight)/2)/igh 1154 | rpistr += " -roi " + str(zxo) + "," + str(zyo) + "," + str(zwidth/igw) + "," + str(zheight/igh) 1155 | if zoom == 10: 1156 | rpistr += " -w " + str(preview_width) + " -h " + str(preview_height) 1157 | zxo = ((zx -((preview_width/2) / (igw/preview_width)))/preview_width) 1158 | zyo = ((zy -((preview_height/2) / (igh/preview_height)))/preview_height) 1159 | rpistr += " -roi " + str(zxo) + "," + str(zyo) + "," + str(preview_width/igw) + "," + str(preview_height/igh) 1160 | #print (rpistr) 1161 | os.system(rpistr) 1162 | while not os.path.exists(fname): 1163 | pass 1164 | image = pygame.image.load(fname) 1165 | catSurfacesmall = pygame.transform.scale(image, (preview_width,preview_height)) 1166 | windowSurfaceObj.blit(catSurfacesmall, (0, 0)) 1167 | text(0,0,6,2,1,fname,int(fv*1.5),1) 1168 | pygame.display.update() 1169 | time.sleep(2) 1170 | button(0,0,0,4) 1171 | text(0,0,1,0,1,"CAPTURE",ft,7) 1172 | text(1,0,1,0,1,"CAPTURE",ft,7) 1173 | text(1,0,1,1,1,"Video",ft,7) 1174 | text(0,0,1,1,1,"Still",ft,7) 1175 | text(1,6,1,0,1,"CAPTURE",ft,7) 1176 | text(1,6,1,1,1,"Timelapse",ft,7) 1177 | restart = 2 1178 | 1179 | if button_column == 2: 1180 | if button_row == 1: 1181 | # video 1182 | os.killpg(p.pid, signal.SIGTERM) 1183 | button(1,0,1,3) 1184 | text(1,0,2,0,1,"CAPTURE",ft,0) 1185 | text(0,0,0,0,1,"CAPTURE",ft,7) 1186 | text(0,0,0,1,1,"Still",ft,7) 1187 | text(1,6,0,0,1,"CAPTURE",ft,7) 1188 | text(1,6,0,1,1,"Timelapse",ft,7) 1189 | text(0,0,6,2,1,"Please Wait, taking video ...",int(fv*1.7),1) 1190 | now = datetime.datetime.now() 1191 | timestamp = now.strftime("%y%m%d%H%M%S") 1192 | vname = vid_dir + str(timestamp) + '.h264' 1193 | rpistr = "raspivid -t " + str(vlen * 1000) 1194 | if zoom == 0: 1195 | rpistr += " -w " + str(vwidth) + " -h " + str(vheight) 1196 | elif zoom > 0 : 1197 | rpistr += " -w " + str(preview_width) + " -h " + str(preview_height) 1198 | if zoom > 0 and Pi_Cam != 3: 1199 | rpistr += " --mode 2" 1200 | if zoom > 0 and Pi_Cam == 3: 1201 | rpistr += " --mode 3" 1202 | speed2 = sspeed 1203 | if mode == 0: 1204 | rpistr +=" -ex off -ss " + str(speed2) + " -fps " + str(fps) 1205 | elif modes[mode] == "fixedfps": 1206 | rpistr +=" -ex fixedfps -ss " + str(speed2) + " -fps " + str(fps) 1207 | else: 1208 | rpistr +=" -ex " + str(modes[mode]) + " -ev " + str(ev) + " -fps " + str(fps) 1209 | rpistr += " -p 0,0," + str(preview_width) + "," + str(preview_height) + " -o " + vname + " -co " + str(contrast) + " -br " + str(brightness) 1210 | rpistr += " -awb off -awbg " + str(red) + "," + str(blue) + " -ISO " + str(ISO) 1211 | if awb == 0: 1212 | rpistr += " -awb off -awbg " + str(red) + "," + str(blue) 1213 | else: 1214 | rpistr += " -awb " + awbs[awb] 1215 | if effect > 0: 1216 | rpistr += " -ifx " + effects[effect] 1217 | if meter > 0: 1218 | rpistr += " -mm " + meters[meter] 1219 | if flicker > 0: 1220 | rpistr += " -fli " + flickers[flicker] 1221 | if drc > 0: 1222 | rpistr += " -drc " + drcs[drc] 1223 | if a_video == 1: 1224 | rpistr += " -a 12 -a '%d-%m-%Y %X' -ae 32,0x8080ff" 1225 | if a_video == 2: 1226 | rpistr += " -a 12 -a 16 -a 64 " 1227 | if zoom > 0 and zoom < 10: 1228 | zwidth = preview_width * (5-zoom) 1229 | if zwidth > igw: 1230 | zwidth = igw - int(igw/20) 1231 | zheight = preview_height * (5-zoom) 1232 | if zheight > igh: 1233 | zheight = igh - int(igh/20) 1234 | zxo = ((igw-zwidth)/2)/igw 1235 | zyo = ((igh-zheight)/2)/igh 1236 | rpistr += " -roi " + str(zxo) + "," + str(zyo) + "," + str(zwidth/igw) + "," + str(zheight/igh) 1237 | if zoom == 10: 1238 | zxo = ((zx -((preview_width/2) / (igw/preview_width)))/preview_width) 1239 | zyo = ((zy -((preview_height/2) / (igh/preview_height)))/preview_height) 1240 | rpistr += " -roi " + str(zxo) + "," + str(zyo) + "," + str(preview_width/igw) + "," + str(preview_height/igh) 1241 | 1242 | #print (rpistr) 1243 | os.system(rpistr) 1244 | text(0,0,6,2,1,vname,int(fv*1.5),1) 1245 | time.sleep(1) 1246 | button(1,0,0,3) 1247 | text(0,0,1,0,1,"CAPTURE",ft,7) 1248 | text(0,0,1,1,1,"Still",ft,7) 1249 | text(1,0,1,0,1,"CAPTURE",ft,7) 1250 | text(1,0,1,1,1,"Video",ft,7) 1251 | text(1,6,1,0,1,"CAPTURE",ft,7) 1252 | text(1,6,1,1,1,"Timelapse",ft,7) 1253 | restart = 2 1254 | 1255 | elif button_row == 7: 1256 | # timelapse 1257 | os.killpg(p.pid, signal.SIGTERM) 1258 | button(1,6,1,2) 1259 | text(0,0,0,0,1,"CAPTURE",ft,7) 1260 | text(1,0,0,0,1,"CAPTURE",ft,7) 1261 | text(1,0,0,1,1,"Video",ft,7) 1262 | text(0,0,0,1,1,"Still",ft,7) 1263 | text(1,6,2,0,1,"CAPTURE",ft,0) 1264 | text(1,6,2,1,1,"Timelapse",ft,0) 1265 | tcount = 0 1266 | if tinterval < 20: 1267 | text(0,0,6,2,1,"Please Wait, taking Timelapse ...",int(fv*1.7),1) 1268 | rpistr = "raspistill -n -t " + str(tduration * 1000) + " -tl " + str(tinterval * 1000) + " -o /home/pi/Pictures/%04d.jpg -dt" 1269 | rpistr += " -bm -co " + str(contrast) + " -br " + str(brightness) 1270 | rpistr += " -awb off -awbg " + str(red) + "," + str(blue) 1271 | if modes[mode] != 'off': 1272 | rpistr += " -ex " + modes[mode] 1273 | else: 1274 | rpistr += " -ex off -ss " + str(sspeed) 1275 | if ISO > 0 and modes[mode] != 'off': 1276 | rpistr += " -ISO " + str(ISO) 1277 | if ev != 0 and modes[mode] != 'off': 1278 | rpistr += " -ev " + str(ev) 1279 | if awb == 0: 1280 | rpistr += " -awb off -awbg " + str(red) + "," + str(blue) 1281 | else: 1282 | rpistr += " -awb " + awbs[awb] 1283 | if effect > 0: 1284 | rpistr += " -ifx " + effects[effect] 1285 | if meter > 0: 1286 | rpistr += " -mm " + meters[meter] 1287 | if flicker > 0: 1288 | rpistr += " -fli " + flickers[flicker] 1289 | if drc > 0: 1290 | rpistr += " -drc " + drcs[drc] 1291 | if zoom > 0 and zoom < 10: 1292 | zwidth = preview_width * (5-zoom) 1293 | if zwidth > igw: 1294 | zwidth = igw - int(igw/20) 1295 | zheight = preview_height * (5-zoom) 1296 | if zheight > igh: 1297 | zheight = igh - int(igh/20) 1298 | rpistr += " -w " + str(zwidth) + " -h " + str(zheight) 1299 | zxo = ((igw-zwidth)/2)/igw 1300 | zyo = ((igh-zheight)/2)/igh 1301 | rpistr += " -roi " + str(zxo) + "," + str(zyo) + "," + str(zwidth/igw) + "," + str(zheight/igh) 1302 | if zoom == 10: 1303 | rpistr += " -w " + str(preview_width) + " -h " + str(preview_height) 1304 | zxo = ((zx -((preview_width/2) / (igw/preview_width)))/preview_width) 1305 | zyo = ((zy -((preview_height/2) / (igh/preview_height)))/preview_height) 1306 | rpistr += " -roi " + str(zxo) + "," + str(zyo) + "," + str(preview_width/igw) + "," + str(preview_height/igh) 1307 | os.system(rpistr) 1308 | else: 1309 | while tcount < tshots: 1310 | tstart = time.monotonic() 1311 | text(0,0,6,2,1,"Please Wait, taking Timelapse ...",int(fv*1.7),1) 1312 | now = datetime.datetime.now() 1313 | timestamp = now.strftime("%y%m%d%H%M%S") 1314 | fname = pic_dir + str(timestamp) + '_' + str(tcount) + '.jpg' 1315 | if speed < 6000001: 1316 | rpistr = "raspistill -p 0,0," + str(preview_width) + "," + str(preview_height) + " -o " + str(fname) + " -co " + str(contrast) + " -br " + str(brightness) 1317 | rpistr += " -awb off -awbg " + str(red) + "," + str(blue) 1318 | if modes[mode] != 'off': 1319 | rpistr += " -t 800 -ex " + modes[mode] 1320 | else: 1321 | rpistr += " -t 500 -ex off -ss " + str(sspeed) 1322 | if ISO > 0 and modes[mode] != 'off': 1323 | rpistr += " -ISO " + str(ISO) 1324 | if ev != 0 and modes[mode] != 'off': 1325 | rpistr += " -ev " + str(ev) 1326 | else: 1327 | rpistr = "raspistill -t " + str(tcount) + " -tl " + str(tinterval) + " -md 3 -bm -ex off -ag 1 -ss " + str(speed) + " -st -o " + fname 1328 | rpistr += " -co " + str(contrast) + " -br " + str(brightness) 1329 | rpistr += " -awb off -awbg " + str(red) + "," + str(blue) 1330 | rpistr += " -n " 1331 | if awb == 0: 1332 | rpistr += " -awb off -awbg " + str(red) + "," + str(blue) 1333 | else: 1334 | rpistr += " -awb " + awbs[awb] 1335 | if effect > 0: 1336 | rpistr += " -ifx " + effects[effect] 1337 | if meter > 0: 1338 | rpistr += " -mm " + meters[meter] 1339 | if flicker > 0: 1340 | rpistr += " -fli " + flickers[flicker] 1341 | if drc > 0: 1342 | rpistr += " -drc " + drcs[drc] 1343 | zwidth = preview_width * (5-zoom) 1344 | zheight = preview_height * (5-zoom) 1345 | if zoom == 10: 1346 | rpistr += " -w " + str(preview_width) + " -h " + str(preview_height) 1347 | else: 1348 | rpistr += " -w " + str(zwidth) + " -h " + str(zheight) 1349 | if zoom > 0 and zoom < 10: 1350 | zwidth = preview_width * (5-zoom) 1351 | if zwidth > igw: 1352 | zwidth = igw - int(igw/20) 1353 | zheight = preview_height * (5-zoom) 1354 | if zheight > igh: 1355 | zheight = igh - int(igh/20) 1356 | zxo = ((igw-zwidth)/2)/igw 1357 | zyo = ((igh-zheight)/2)/igh 1358 | rpistr += " -roi " + str(zxo) + "," + str(zyo) + "," + str(zwidth/igw) + "," + str(zheight/igh) 1359 | if zoom == 10: 1360 | zxo = ((zx -((preview_width/2) / (igw/preview_width)))/preview_width) 1361 | zyo = ((zy -((preview_height/2) / (igh/preview_height)))/preview_height) 1362 | rpistr += " -roi " + str(zxo) + "," + str(zyo) + "," + str(preview_width/igw) + "," + str(preview_height/igh) 1363 | os.system(rpistr) 1364 | while not os.path.exists(fname): 1365 | pass 1366 | image = pygame.image.load(fname) 1367 | catSurfacesmall = pygame.transform.scale(image, (preview_width,preview_height)) 1368 | windowSurfaceObj.blit(catSurfacesmall, (0, 0)) 1369 | text(0,0,6,2,1,fname,int(fv*1.5),1) 1370 | pygame.display.update() 1371 | tcount +=1 1372 | while time.monotonic() - tstart < tinterval and tcount < tshots: 1373 | for event in pygame.event.get(): 1374 | if (event.type == MOUSEBUTTONUP): 1375 | mousex, mousey = event.pos 1376 | if mousex > preview_width: 1377 | e = int((mousex-preview_width)/int(bw/2)) 1378 | f = int(mousey/bh) 1379 | g = (f*4) + e 1380 | if g == 30 or g == 31: 1381 | tcount = tshots 1382 | button(1,6,0,2) 1383 | text(0,0,1,0,1,"CAPTURE",ft,7) 1384 | text(1,0,1,0,1,"CAPTURE",ft,7) 1385 | text(1,0,1,1,1,"Video",ft,7) 1386 | text(0,0,1,1,1,"Still",ft,7) 1387 | text(1,6,1,0,1,"CAPTURE",ft,7) 1388 | text(1,6,1,1,1,"Timelapse",ft,7) 1389 | restart = 2 1390 | if restart > 0: 1391 | if restart == 1: 1392 | os.killpg(p.pid, signal.SIGTERM) 1393 | text(0,0,6,2,1,"Waiting for preview ...",int(fv*1.7),1) 1394 | preview() 1395 | 1396 | 1397 | 1398 | 1399 | 1400 | 1401 | 1402 | 1403 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pi-Camera-GUI 2 | 3 | # NOTE: Will NOT work with RaspiOS based on BULLSEYE or BOOKWORM... new version at https://github.com/Gordon999/RPiCamGUI 4 | 5 | Script to allow control of a Pi Camera. Will work with all models, v1, v2 & HQ 6 | 7 | Shows a reduced preview but saves stills at camera full resolution *, and videos at user set resolution *. 8 | 9 | * Will save images and videos at preview size if zoom or focus button activated 10 | 11 | With a Pi HQ Camera will allow exposures upto 239 seconds. 12 | 13 | Click mouse on the left of a button to decrease, right to increase or use the appropriate slider 14 | 15 | Always use the EXIT button to EXIT 16 | 17 | Requires opencv installed sudo apt-get install python3-opencv 18 | 19 | ## Screenshot 20 | 21 | ![screenshot](screenshot.jpg) 22 | 23 | ## Zoomed 24 | 25 | ![screenshot](zoomed.jpg) 26 | -------------------------------------------------------------------------------- /screen002.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gordon999/Pi-Camera-GUI/86c395bfbe8bd28143e7e7ed921fc6fa9bef8624/screen002.jpg -------------------------------------------------------------------------------- /screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gordon999/Pi-Camera-GUI/86c395bfbe8bd28143e7e7ed921fc6fa9bef8624/screenshot.jpg -------------------------------------------------------------------------------- /zoomed.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gordon999/Pi-Camera-GUI/86c395bfbe8bd28143e7e7ed921fc6fa9bef8624/zoomed.jpg --------------------------------------------------------------------------------