Skip to content
DuolixDuolix
HomeAll RobotsKits & partsEvents

My

Saved itemsOrders

Explore

Developer docsCommunity
AboutSupportPrivacy

© 2026 Duolix

Duolix
Developer documentationSDK reference
All documentation
Start hereDevelopment overviewQuick startConnect to the device
QCS6490 hardwareQCS6490 hardware overviewQCS6490 interfacesQCS6490 bring-up
AidLux systemAidLux workspaceNetwork and remote accessDevelopment environmentStart an application at boot
AI developmentInference workflowAidLite SDKROS 2 integration
SDK referenceAidLite Python APIAidLite C++ APIAidCV Python APIAidConnect C++ APIAidConnect Android APIAidStream C++ APIAidVoice C++ API
TroubleshootingTroubleshooting
SDK reference

AidCV Python API

Camera and image-processing interfaces.

Create Window namedWindow

Field 1Field 2Field 3Field 4Field 5
APInamedWindow(winname, flags = 0, size = None, port = None) -> None———
ParametersParameter NameTypeDefault ValueDescription
winnamestrNo defaultWindow name bound to the window, must be unique.—
flagsint0Window properties, invalid parameter, kept for OpenCV compatibility.—
sizeNo restrictionNoneWindow size, first value is width, second is height, in the form of [width, height].—
portintNonePort number to use, a random port will be used when default or unusable port is provided.—
Return ValueNone———

Builds a web page using the specified port or a random port, while creating a window in the Web Desktop pointing to this page. The web page is bound to the winname, and based on this winname, developers can use other APIs to affect this web page. When multiple Web Desktops are open, this window will appear in each Web Desktop.

Note: Unlike OpenCV, windows created in the Web Desktop cannot be freely resized. If developers want to control the window size to match the image, please explicitly pass the size parameter when using this API.

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2

cv2.namedWindow("win0")

cv2.namedWindow("win1", cv2.WINDOW_AUTOSIZE)

cv2.namedWindow("win2", size = (640,480))

cv2.namedWindow("win3", cv2.WINDOW_AUTOSIZE, size = (640,480))

Register Mouse Callback Function setMouseCallback

Field 1Field 2Field 3Field 4Field 5
APIsetMouseCallback(winname, onMouse, userdata = 0) -> None———
ParametersParameter NameTypeDefault ValueDescription
winnamestrNo defaultName bound to the target window.—
onMousefunctionNo defaultCallback function that will be called when the mouse clicks on the target window. The callback function must follow this format: call_back(event, x, y, flags, param). Where event is the constant corresponding to the triggered mouse event type, consistent with OpenCV's definition. x, y are the click positions of the mouse. flags is a constant for mouse event flags, an invalid parameter kept for OpenCV compatibility. param is the parameter passed in by the developer, which is the third parameter of the setMouseCallback function.—
userdataNo restriction0Optional parameter passed to the callback function, custom external data defined by the developer.—
Return ValueNone———

Sets the mouse callback function for the specified window, currently only responds to mouse click events.

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2

import time

def call_back(event, x, y, flags, params):
    print(event,x,y,params)

cv2.namedWindow("win")
cv2.setMouseCallback("win", call_back)
time.sleep(10)

Wait for Key Event waitKey

Field 1Field 2Field 3Field 4Field 5
APIwaitKey(delay = 0) -> int or str———
ParametersParameter NameTypeDefault ValueDescription
delayint0Timeout in milliseconds, will wait indefinitely for a key event when value is less than or equal to 0.—
Return ValueConstant of int or str type, representing the ASCII code or name of the captured key.———

Captures the next keyboard key event.

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2

cv2.namedWindow("aa")
res = cv2.waitKey(10)
print(res)

Display Image imshow

Field 1Field 2Field 3Field 4Field 5
APIimshow(winname, frame, port = None) -> None———
ParametersParameter NameTypeDefault ValueDescription
winnamestrNo defaultName bound to the target window. If the target window does not exist, namedWindow(winname, size = (frame.shape[1], frame.shape[0]), port = port) will be automatically called to create the window.—
framenumpy.arrayNo defaultImage data to be displayed, typically BGR color image data is provided and displayed as RGB color.—
Return ValueNone———

Displays the specified image in the target window.

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2
import time

frame = cv2.imread("test.jpg")

cv2.namedWindow("win0")

cv2.imshow("win0", frame)
cv2.imshow("win1", frame)

time.sleep(5)

Destroy Window destroyWindow

Field 1Field 2Field 3Field 4Field 5
APIdestroyWindow(winname) -> None———
ParametersParameter NameTypeDefault ValueDescription
winnamestrNo defaultName bound to the target window.—
Return ValueNone———

Destroys and closes the window named winname.

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2
import time

cv2.namedWindow("win0")
cv2.namedWindow("win1")

time.sleep(3)
cv2.destroyWindow("win0")
time.sleep(5)

Destroy All Windows destroyAllWindows

Field 1Field 2
APIdestroyAllWindows() -> None
ParametersNone
Return ValueNone

Destroys and closes all windows opened by the current process.

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2
import time

cv2.namedWindow("win0")
cv2.namedWindow("win1")

time.sleep(3)
cv2.destroyAllWindows()
time.sleep(5)

Class VideoCapture

The VideoCapture class is used to capture video frames from cameras or video files. It supports USB cameras and MIPI cameras. Due to underlying limitations, it currently does not support opening multiple MIPI cameras simultaneously. When used without extended parameters, it behaves consistent with cv2.VideoCapture; using extended parameters initializes the VideoCapture object with AidCV extensions.

Initialization

The VideoCapture class has two initialization methods.

Field 1Field 2
InitializationVideoCapture()
ParametersNone
Return ValueAn initialized VideoCapture instance.
Field 1Field 2Field 3Field 4Field 5
InitializationVideoCapture(filename, apiPreference = 0, device = "usb")———
ParametersParameter NameTypeDefault ValueDescription
filenamestr or intNo defaultVideo filename, USB camera node name, or MIPI camera index (0 for front camera, 1 for rear camera).—
apiPreferenceint0Backend selection, invalid parameter, kept for OpenCV compatibility.—
devicestr"usb"Camera type, available values are "usb", "mipi".—
Return ValueAn initialized VideoCapture instance that has opened the specified device or file.———

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2

cap = cv2.VideoCapture()

file_cap = cv2.VideoCapture("/home/aidlux/test.mp4")

usb_cap = cv2.VideoCapture("/dev/video2")

mipi_cap = cv2.VideoCapture(0, device = "mipi")

Member Functions

Field 1Field 2Field 3Field 4Field 5
Member FunctionVideoCapture().open(filename, apiPreference = 0) -> None———
ParametersParameter NameTypeDefault ValueDescription
filenamestr or intNo defaultVideo filename, USB camera node name, or MIPI camera index (0 for front camera, 1 for rear camera).—
apiPreferenceint0Backend selection, invalid parameter, kept for OpenCV compatibility.—
Return ValueNone———

Opens a camera or file.

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2

cap = cv2.VideoCapture()
cap.open("/dev/video2")

Field 1Field 2
Member FunctionVideoCapture().isOpened() -> bool
ParametersNone
Return ValueBoolean constant indicating whether the camera has been successfully opened.

Opens the corresponding device or file. If the VideoCapture instance has already opened a camera, this function will not perform any operation.

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2

cap = cv2.VideoCapture("/dev/video2")

print(cap.isOpened())
Field 1Field 2
Member FunctionVideoCapture().read() -> (bool, numpy.array)
ParametersNone
Return Value(ret, frame) ret: Boolean constant indicating success or failure of capture. frame: Numpy array, the captured video frame.

Captures an image frame from an opened device or file.

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2

cap = cv2.VideoCapture("/dev/video2")

ret, frame = cap.read()
if ret:
  print(frame.shape)

Field 1Field 2Field 3Field 4Field 5
Member FunctionVideoCapture().get(propId) -> float———
ParametersParameter NameTypeDefault ValueDescription
propIdintNo defaultParameter index, maximum value is 18. The parameters corresponding to each index are consistent with OpenCV. Due to underlying implementation issues, when device="mipi", currently only 3: width, 4: height, 5: frame rate are effective.—
Return ValueConstant representing the value of the corresponding parameter.———

Gets the default parameters of the camera.

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2

cap = cv2.VideoCapture("/dev/video2")
print(cap.get(3), cap.get(4))

Field 1Field 2Field 3Field 4Field 5
Member FunctionVideoCapture().set(propId, value) -> bool———
ParametersParameter NameTypeDefault ValueDescription
propIdintNo defaultParameter index, maximum value is 18. The parameters corresponding to each index are consistent with OpenCV. Due to underlying implementation issues, when device="mipi", currently only 3: width, 4: height, 5: frame rate are effective.—
valueintNo defaultValue to be set for the corresponding parameter.—
Return ValueBoolean constant indicating whether the parameter setting was successful.———

Sets the specified parameter of the camera. The parameter to be specified and its value must be within the range allowed by the camera.

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2

cap = cv2.VideoCapture("/dev/video2")
cap.set(3, 1920)
cap.set(4, 1080)
cap.set(5, 30)
ret, frame = cap.read()
print(frame.shape)

Field 1Field 2
Member FunctionVideoCapture().release()
ParametersNone
Return ValueNone

Releases the camera opened by this VideoCapture instance.

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2

cap = cv2.VideoCapture("/dev/video2")

cap.release()

Mathematical Calculation sigmoid

Field 1Field 2Field 3Field 4Field 5
APIsigmoid(x) -> numpy.array———
ParametersParameter NameTypeDefault ValueDescription
xnumpy.arrayNo defaultIndependent variable of the sigmoid function.—
Return ValueConstant of numpy.array type, with the same shape as parameter x, representing the value of parameter x after calculation by the sigmoid function.———

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2

x = np.array(range(8)).reshape(2,2,2)
print(cv2.sigmoid(x))

Mathematical Calculation softmax

Field 1Field 2Field 3Field 4Field 5
APIsoftmax(x, axis = 0) -> numpy.array———
ParametersParameter NameTypeDefault ValueDescription
xnumpy.arrayNo defaultIndependent variable of the softmax function.—
axisint0Performs calculation along the specified axis.—
Return ValueConstant of numpy.array type, with the same shape as parameter x, representing the value of parameter x on the specified axis after calculation by the softmax function.———

Usage Example

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2

x = np.array(range(8)).reshape(2,2,2)
print(cv2.softmax(x, axis = 2))

Generate Color Mask: colormask

Field 1Field 2Field 3Field 4Field 5
APIcolormask(mask, color) -> list———
ParametersNameTypeDefaultDescription
masknumpy.arrayNoneA 2D or 3D mask. 2D masks should be of int type, and 3D masks should be of float type.—
colorlistNoneA list of mapped colors, each represented by a 3-tuple (r, g, b).—
Return[color_mask] or [color_mask,...] [color_mask]: A 2D mask returns one color mask image, where each position indicates the class it belongs to. [color_mask,...]: A 3D mask returns a list of color masks, each representing the probability of belonging to a specific class.———

Uses the color to map a 2D or 3D mask mask into a color image. The mapping logic is as follows:

  • For 2D masks, the value at each position in the mask is an integer (e.g., 0, 1, 2,...), which is treated as the class index. Different values map to different colors.
  • For 3D masks, the third dimension represents different classes. The first two dimensions hold the probability that the position belongs to each class. Each class maps to a different color.

Example Usage

try: # aidcv-sdk>=1.0.4
    import aidcv as cv2
except:
    import cv2
import numpy as np

mask = np.array([[1, -1, 0], [2, 0, -2], [0, 3, -3]])[None]
colors = [(0,255,255)]
res = cv2.colormask(mask, colors)[0]
print(mask)
res = cv2.resize(res, (500,500), interpolation = cv2.INTER_NEAREST)
cv2.namedWindow("win0")
cv2.imshow("win0", res)
cv2.waitKey(3000)
print("next example")

mask = np.array([[1, 3, 0], [2, 0, 0], [0, 3, 0]])
colors = [(0,255,255),(255,0,0),(0,255,0),(0,0,255)]
res = cv2.colormask(mask, colors)[0]
print(mask)
res = cv2.resize(res, (500,500), interpolation = cv2.INTER_NEAREST)
cv2.imshow("win0", res)
cv2.waitKey(3000)
print("over")
PreviousAidLite C++ APINextAidConnect C++ API