This code will let you view a live MJPEG stream inside a gui. My original need for this functionality was to view python opencv output in my gui. See this thread for discussion viewtopic.php?f=76&t=81795&hilit=opencv
The heavy lifting is done by an activex plugin that can be accessed by installing the media control sdk that was provided by axis communications Axis-Media-Control. You do need to create an account to download the sdk, but it is free.
For testing I created a MJPEG stream using python and opencv. And connected to the stream using viewer.ahk
The python scripts create a webserver that pushes the modified frames from opencv. When the viewer.ahk navigates to the stream the viewer plugin will be installed.
main.py creates the flask webserver to host index.html
import cv2
import numpy as np
class VideoCamera(object):
def __init__(self):
self.video = cv2.VideoCapture(0,cv2.CAP_DSHOW)
def __del__(self):
self.video.release()
def get_frame(self):
success, im = self.video.read()
imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 127, 255, 0)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(im, contours, -1, (0,255,0), 3)
# We are using Motion JPEG, but OpenCV defaults to capture raw images,
# so we must encode it into JPEG in order to correctly display the
# video stream.
ret, jpeg = cv2.imencode('.jpg', im)
return jpeg.tobytes()
index.hml has code to load activex plugin to begin stream
Do you really need to use an activex plugin for this? Seems like you can just set an img tags src property to the url and it will automatically stream the mjpeg
kczx3 wrote:Do you really need to use an activex plugin for this?
Maybe not? In my experience the code from stack overflow was a turnkey solution for all browsers except for IE and internal gui. On IE and gui it resulted in a black x where image should be like image not found. If it works for you turn key I would be very interested in the details of your settings/setup.
Ah I see. The only times I’ve played with python and cameras was with a RaspberryPi and that used Chromium so I had no issues. You could try to use WebView2. I have a post in the v2 scripts forum that hosts the Chromium based Edge in a GUI.
Embedding edge would do the trick, I'll keep this solution in mind. Unfortunately, I have yet to make the leap to v2. I am not sure if I ever will, kinda getting set in my ways. I will add this to my growing list of benefits of upgrading.