I write a script based on opencv pacakge to capture the video streaming.
As is shown, now I want to show the image on the red slice view ,what should I do?
I know Plus can help,but that is not what I want on my project.
def onCamera(self):
with slicer.util.tryWithErrorDisplay("Failed to compute results.", waitCursor=True):
if self.ui.camButton.text =="Start":
self.ui.camButton.text = "Stop"
self.timer.connect('timeout()', self.ImageShow)
self.timer.start()
self.cap = cv2.VideoCapture(0)
self.cap.set(cv2.CAP_PROP_BUFFERSIZE, 3)
self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, 500)
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 500)
else:
self.ui.camButton.text = "Start"
self.timer.stop()
self.cap.release()
def ImageShow(self):
try:
if self.cap.isOpened() != 1:
return
ret, img = self.cap.read()
cv2.imwrite('temp.jpg', img, [cv2.IMWRITE_PNG_BILEVEL, 0])
Pic = qt.QPixmap('temp.jpg')
self.ui.imageBox.setPixmap(Pic)
self.ui.imageBox.setScaledContents(True)
except Exception as e:
print('%s' % e)