- Version: 20261019
- Source Code Copyright: Unknown
- Vendored OpenCV 4.5.5 headers, import library and DLL (src/OpenCV/include/opencv/, src/OpenCV/x64/Release/opencv_world455.dll): Apache License 2.0 (OpenCV license).
- Vendored Font Awesome 4.7.0 icon fonts (src/application/template/src/assets/static/fonts/icons/fontawesome/; the font metadata points to the Font Awesome license page): SIL Open Font License 1.1 (Font Awesome 4 license).
- Themify icon font and lena.png (same assets/static/ folder): Unknown (no license is included in the folder).
- Redistribution Restriction: This source code is integrated by LEADERG INC. Please use it privately. Please DO NOT distribute it to internet.
Web webcam viewer with a C++ capture engine, launched from Jupyter, for Windows x64. A Python aiohttp server (http://127.0.0.1:8080/) loads a small C++ DLL (OpenCV.dll, built with Visual Studio against OpenCV 4.5.5) through ctypes. When you click Start on the web page, the DLL opens camera 0 with DirectShow and grabs frames on a background thread; the page then polls /api/GetImageBuffer every 100 ms and shows each frame as a base64-encoded PNG. Stop ends the capture. The notebook Web-OpenCV-Webcam.ipynb is only a launcher: it starts the server in a new console window. Image-OpenCV-CPP-Web-Webcam, which was migrated from this project, is its newer counterpart.
[Folder Structure]
- copyright.txt: Copyright notice.
- Image-OpenCV-CPP-Web-Webcam-Jupyter.html: This document (usage page).
- Web-OpenCV-Webcam.ipynb: Jupyter launcher: runs python src/server.py in a new console window.
- src/server.py: aiohttp entry point: registers the routes, opens http://127.0.0.1:8080/ in the default browser and serves on 127.0.0.1:8080.
- src/application/: Web app: routes.py (URL routes), views.py (page views), API.py (loads OpenCV.dll with ctypes and implements the capture API), config/settings.py (template and static paths) and template/src/ (index.html, assets/scripts/main.js, assets/styles/style.css). template/src/assets/static/ also holds icon fonts and images/lena.png, which the page does not use.
- src/OpenCV/library.cpp: C++ capture engine. Exports OpenCV_StartCapture, OpenCV_GetImageInfo, OpenCV_GetImageBuffer, OpenCV_StopCapture and OpenCV_RegisterCallback.
- src/OpenCV/library.sln, library.vcxproj (with .filters and .user): Visual Studio solution and project (Visual Studio 2015 format, toolset v140, Windows SDK 8.1, Release | x64 only) that builds OpenCV.dll.
- src/OpenCV/include/opencv/: Vendored OpenCV 4.5.5 for Windows x64 (readme.txt: opencv-4.5.5-win64): include/opencv2/ headers, lib/opencv_world455.lib and dll/opencv_world455.dll (about 64 MB).
- src/OpenCV/x64/Release/: Prebuilt OpenCV.dll (14 KB), a copy of opencv_world455.dll, and Visual Studio build intermediates (.obj, .lib, .tlog, logs). API.py loads the DLL from here.
[Prerequisites]
- Windows x64. The DLLs are x64 builds, capture uses DirectShow, and the notebook uses subprocess.CREATE_NEW_CONSOLE.
- 64-bit Python 3.8 or later, because API.py calls os.add_dll_directory(), which Python 3.8 added. The notebook metadata records Python 3.7.6, the version it was saved with.
- pip packages imported by the code: aiohttp, aiohttp-jinja2, jinja2, numpy, opencv-python: pip install aiohttp aiohttp-jinja2 jinja2 numpy opencv-python
- Microsoft Visual C++ 2015-2022 Redistributable (x64). OpenCV.dll imports VCRUNTIME140.dll, and opencv_world455.dll imports MSVCP140.dll, CONCRT140.dll and VCRUNTIME140.dll.
- A webcam (camera index 0).
- Jupyter Notebook or JupyterLab, only if you use the notebook launcher.
- To rebuild OpenCV.dll: Visual Studio with the C++ desktop workload. The project targets toolset v140 (Visual Studio 2015) and Windows SDK 8.1, so newer Visual Studio versions may need to retarget it.
[How to Run]
Option A: Jupyter notebook
- Start Jupyter so that the project folder is the notebook's working directory, then open Web-OpenCV-Webcam.ipynb.
- Run all cells. The last cell runs python src/server.py in a new console window, so python on PATH must be the interpreter with the packages above. The cell keeps running until the server exits.
Option B: command prompt
Start the server from the project root. API.py finds the DLLs at src\OpenCV\x64\Release relative to the current working directory.
REM run from the project root folder
python src\server.py
Using the page
- The server prints server start and opens http://127.0.0.1:8080/ in the default browser.
- Click Start. If camera 0 opens, the frames appear on the right and refresh every 100 ms. If it does not open, the browser shows the alert Camera is not Opened.
- Click Stop to stop capturing and release the camera.
- To stop the server, close its console window or press Ctrl+C in it.
[Web API]
- /, /index.html — Method: GET; Behavior: The web page (Start and Stop buttons, plus an image area).
- /api/OpenStart — Method: GET; Behavior: Calls OpenCV_StartCapture(0), waits 1 s and reads the frame size. Returns 1 when capture is running, or 0 if the camera cannot be opened.
- /api/GetImageBuffer — Method: GET; Behavior: Copies the latest frame from the DLL and returns it as an inline base64 PNG {img} snippet.
- /api/OpenStop — Method: GET; Behavior: Calls OpenCV_StopCapture, which stops the capture thread and releases the camera.
- /hello — Method: GET; Behavior: Test text Hello Aiohttp!.
- /api/test_start — Method: POST; Behavior: Test endpoint that returns test_start!.
[Rebuilding the C++ DLL]
- Open src/OpenCV/library.sln in Visual Studio.
- Select Release | x64 and build. The project reads headers from include/opencv/include and links include/opencv/lib/opencv_world455.lib. It writes OpenCV.dll to src/OpenCV/x64/Release/.
- Keep opencv_world455.dll next to OpenCV.dll, because API.py loads the DLLs from that folder. The build does not copy it there; another copy is in src/OpenCV/include/opencv/dll/.
[Notes]
- The sample is Windows-only. Image-OpenCV-CPP-Web-Webcam, which was migrated from this project, is its newer counterpart.
- When API.py is imported, it changes the working directory to src\OpenCV\x64\Release before it loads OpenCV.dll.
- The server listens only on 127.0.0.1, so other machines cannot reach the page.
[Version History]
- 20261019: The folder was renamed from Image-OpenCV-CPP-Web-Webcam-4 to Image-OpenCV-CPP-Web-Webcam-Jupyter-20261019 (the version is now the date of the last change, YYYYMMDD). This usage page was added and the version history moved here from version.txt, which was removed. Image-OpenCV-CPP-Web-Webcam-1, which was migrated from this project, is now Image-OpenCV-CPP-Web-Webcam.
- 4: os.add_dll_directory(dll_path)
- Update OpenCV 4.2.0 => 4.5.5.
- 3: Add copyright statement.
- 2: src/application/API.py: dll_path = os.path.join(os.getcwd(), 'src', 'OpenCV', 'x64', 'Release'), os.chdir(dll_path).
- 1: No description recorded.
This SDK is built in AppForAI - AI Dev Tools.