标签:port == 执行 代码执行 waitkey span show lse python
基于SSVEP的BCI系统需要刺激界面,在PC端用python(主要OpenCV)实现,以下为代码
import cv2 import numpy as np def up(img,flag): for i in range(0,100): for j in range(206,306): if flag: img[i][j]=0 else: img[i][j]=255 def down(img,flag): for i in range(412,512): for j in range(206,306): if flag: img[i][j]=0 else: img[i][j]=255 def left(img,flag): for i in range(206,306): for j in range(0,100): if flag: img[i][j]=0 else: img[i][j]=255 def right(img,flag): for i in range(206,306): for j in range(412,512): if flag: img[i][j]=0 else: img[i][j]=255 if __name__==‘__main__‘: img=np.zeros((512,512,3),np.uint8) up(img,0) down(img,0) left(img,0) right(img,0) cv2.imshow(‘image‘,img) num=0 while 1: num+=1 if num>10000000: num=0 cv2.waitKey(10) if num%5==0: left(img,num%2) if num%6==0: down(img,num/6%2) if num%7==0: right(img,num%2) if num%8==0: up(img,num/8%2) cv2.imshow(‘image‘,img)
效果为:上下左右四个方块按照一定频率闪烁,理论上需要6.25,8,9,10,这里精细度取得比较粗,大概实现功能就OK了,考虑代码执行时间、机器差异,有需要再更改。
标签:port == 执行 代码执行 waitkey span show lse python
原文地址:https://www.cnblogs.com/kangpenglin/p/9363486.html