import numpy as np
import cv2
from mss import mss
from PIL import Image
bounding_box = {'top': 100, 'left': 0, 'width': 400, 'height': 300}
sct = mss()
while True:
sct_img = sct.grab(bounding_box)
cv2.imshow('screen', np.array(sct_img))
if (cv2.waitKey(1) & 0xFF) == ord('q'):
cv2.destroyAllWindows()
break
import numpy as np
import cv2
from mss import mss
from PIL import Image
import threading
from pygame import mixer
class MyMss():
def __init__(self,mss,mixer):
super(MyMss,self).__init__()
self.bounding_box = {'top': 100, 'left': 0, 'width': 400, 'height': 300}
self.mss = mss
self.mixer = mixer
def _grab(self):
while True:
sct_img = self.mss.grab(self.bounding_box)
cv2.imshow('screen', np.array(sct_img))
if (cv2.waitKey(1) & 0xFF) == ord('q'):
cv2.destroyAllWindows()
break
def start_grab(self):
thread = threading.Thread(target=self._grab)
thread.start()
def _music(self):
self.mixer.init()
self.mixer.music.load('fon.mp3')
self.mixer.music.play()
def play_music(self):
m_th = threading.Thread(target=self._music)
m_th.start()
sct = MyMss(mss(),mixer)
sct.start_grab()
sct.play_music()