Skip to content

Commit dd522d6

Browse files
committed
opencv
1 parent fbe6535 commit dd522d6

9 files changed

Lines changed: 60 additions & 27 deletions

File tree

python_game/5.image/yuanse.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import pygame
2+
from pygame.locals import *
3+
from sys import exit
4+
5+
pygame.init()
6+
7+
screen = pygame.display.set_mode((640, 480), 0, 32)
8+
9+
def create_scales(height):
10+
red_scale_surface = pygame.surface.Surface((640, height))
11+
green_scale_surface = pygame.surface.Surface((640, height))
12+
blue_scale_surface = pygame.surface.Surface((640, height))
13+
for x in range(640):
14+
c = int((x/640.)*255.)
15+
red = (c, 0, 0)
16+
green = (0, c, 0)
17+
blue = (0, 0, c)
18+
line_rect = Rect(x, 0, 1, height)
19+
pygame.draw.rect(red_scale_surface, red, line_rect)
20+
pygame.draw.rect(green_scale_surface, green, line_rect)
21+
pygame.draw.rect(blue_scale_surface, blue, line_rect)
22+
return red_scale_surface, green_scale_surface, blue_scale_surface
23+
24+
red_scale, green_scale, blue_scale = create_scales(80)
25+
26+
color = [127, 127, 127]
27+
28+
while True:
29+
30+
for event in pygame.event.get():
31+
if event.type == QUIT:
32+
exit()
33+
34+
screen.fill((0, 0, 0))
35+
36+
screen.blit(red_scale, (0, 00))
37+
screen.blit(green_scale, (0, 80))
38+
screen.blit(blue_scale, (0, 160))
39+
40+
x, y = pygame.mouse.get_pos()
41+
42+
if pygame.mouse.get_pressed()[0]:
43+
for component in range(3):
44+
if y > component*80 and y < (component+1)*80:
45+
color[component] = int((x/639.)*255.)
46+
pygame.display.set_caption("PyGame Color Test - "+str(tuple(color)))
47+
48+
for component in range(3):
49+
pos = ( int((color[component]/255.)*639), component*80+40 )
50+
pygame.draw.circle(screen, (255, 255, 255), pos, 20)
51+
52+
pygame.draw.rect(screen, tuple(color), (0, 240, 640, 240))
53+
54+
pygame.display.update()

python_opencv/1.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#coding:utf-8
22
import cv2
3-
3+
import time
44
capture=cv2.VideoCapture(0)
55
#将capture保存为motion-jpeg,cv_fourcc为保存格式
66
size = (int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)),
@@ -10,6 +10,7 @@
1010
#isopened可以查看摄像头是否开启
1111
print capture.isOpened()
1212
num=0
13+
s = time.ctime()
1314
#要不断读取image需要设置一个循环
1415
while True:
1516
ret,img=capture.read()
@@ -18,7 +19,10 @@
1819
cv2.imshow('Video',img)
1920
key=cv2.waitKey(3)#里面数字为delay时间,如果大于0为刷新时间,
2021
#超过指定时间则返回-1,等于0没有返回值,但也可以读取键盘数值,
21-
cv2.imwrite('%s.jpg'%(str(num)),img)
22+
23+
s = time.ctime()[8:19:1]
24+
print s
25+
cv2.imwrite('%s.jpg' %s,img)
2226
num=num+1
2327
if key==ord('q'):#ord为键盘输入对应的整数,
2428
break

python_opencv/1.py~

Lines changed: 0 additions & 25 deletions
This file was deleted.

python_opencv/2.jpg

105 KB
Loading

python_opencv/psb.jpg

94.8 KB
Loading

python_opencv/psb_face/1.jpg

2.73 KB
Loading

python_opencv/psb_face/2.jpg

-5.02 KB
Loading

python_opencv/psb_face/out.jpg

-2.46 KB
Loading

0 commit comments

Comments
 (0)