Hi,
i have EXE which is doing overlays on a webcam livestream. Its perfectly working on my Laptop with internal and external webcam.
On the other pc the livestream is randomly crashing (without doing anything) after some minutes. I start the EXE with cmd/Windows command and there is no error message when its crashing. So i guess the problem is not the python code? Its maybe a deeper problem: opencv or driver? Do you have a solution to the problem? How i can check whats the error.
here is my working code
def cap_img(self, cap):
ret, img = cap.read()
img = cv2.flip(img,1)#flip cam
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB).copy()
height, width, channel = img.shape
step = channel * width
img = QImage(img.data, width, height, step, QImage.Format_RGB888).copy()
if height != HEIGHT and width != WIDTH:
img = img.scaled(WIDTH, HEIGHT)
return img
def snap_img(self, cap):
ret, img = cap.read()
img = cv2.flip(img,1)
self.snap_cv = img.copy()
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
height, width, channel = img.shape
step = channel * width
self.snap = QImage(img.data, width, height, step, QImage.Format_RGB888).copy()
if height != HEIGHT and width != WIDTH:
self.snap = self.snap.scaled(WIDTH, HEIGHT)
# Show Livestream
def livestream_overlays(self):
super().__init__()
self.overlay_base()
# red lines as overlays
if self.state == 1 or self.state == 2:
self.overlay_red()
elif self.state == 3:
self.overlay_blue()
# Green lines as overlays
if self.lvalue:
self.overlay_green()
# Show livestream with overlays
if self.spsn == True:
img = self.img.scaled(int(w/2), int(h))
self.img2 = self.img2.scaled(int(w/2), int(h))
if self.state_cams == True:
self.show_cam(self.img2,2)
self.show_cam(img,3)
else:
self.show_cam(self.img2,3)
self.show_cam(img,2)
else:
img = self.img.scaled(w, h)
self.show_cam(img,1)
def insertShape(self, img1, lines, linewidth, color):
img = img1.copy()
painter = QPainter()
pixmap = QPixmap(img)
painter.begin(img)
painter.setRenderHint(QPainter.Antialiasing)
painter.drawPixmap(img.rect(), pixmap)
painter.setPen(QPen(colors[color], linewidth))
for line in lines:
painter.drawLine(line[0],line[1],line[2],line[3])
return img
def overlay_base(self):
if self.pop != None:
if self.pop.chns != None:
self.ns = self.pop.chns
self.pop = None
img = self.cap_img(self.cap).copy()
Thank You Guys