You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何用Python读取海康威视DS-2TD2615-10摄像机的热成像温度数据?

Extracting Temperature Data from Hikvision DS-2TD2615-10 Thermal Camera

Hey there, I’ve run into this exact issue with Hikvision thermal cameras before, so let’s break down how to fix this properly. The core problem here is that OpenCV alone can’t get you temperature data—because the RTSP stream you’re pulling (channels/202/) is a rendered RGB heatmap, not the raw thermal sensor data that contains actual temperature values. Let’s walk through the best solutions:

1. Fixing the Hikvision SDK Approach (The Reliable Way)

I’m guessing your earlier SDK attempts didn’t target the right thermal data APIs—Hikvision’s SDK has specific functions for thermal cameras that you need to use instead of generic video stream calls. Here’s a Python example using a maintained Hikvision SDK wrapper that should work for your camera:

First, install the community-maintained SDK wrapper:

pip install hikvisionapi

Then use this code to get temperature arrays and add click-to-get-temperature functionality:

import cv2
from hikvisionapi import Client

# Initialize camera connection
cam = Client('http://YOUR_CAMERA_IP', 'USERNAME', 'PASSWORD', timeout=30)
# Switch to thermal mode (adjust the value if needed per your camera's SDK docs)
cam.select_detection_method(2)

# Get the thermal stream that includes raw temperature data
thermal_stream = cam.stream('Thermal')

# Mouse callback function to fetch temperature on click
def get_temp_on_click(event, x, y, flags, param):
    if event == cv2.EVENT_LBUTTONDOWN:
        # Validate coordinates are within frame bounds
        if 0 <= x < temp_array.shape[1] and 0 <= y < temp_array.shape[0]:
            temp = temp_array[y][x]
            print(f"Temperature at ({x}, {y}): {temp:.2f}°C")

cv2.namedWindow('Thermal Frame')
cv2.setMouseCallback('Thermal Frame', get_temp_on_click)

while True:
    # Read frame and temperature data (wrapper returns both)
    frame_data = thermal_stream.read()
    temp_array = frame_data['temperature']  # 2D array matching frame resolution
    img = frame_data['image']

    cv2.imshow('Thermal Frame', img)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Cleanup resources
thermal_stream.close()
cam.close()
cv2.destroyAllWindows()

Key Notes for SDK Success:

  • Skip RTSP for temperature data: The RTSP stream (channels/202/) is just a visual heatmap—you need the SDK’s dedicated thermal endpoints to get actual temperature values.
  • Check camera permissions: Ensure your user account has access to thermal data (verify in the camera’s web interface under "Permissions" > "Thermal Settings").
  • Keep SDK/firmware updated: Use the latest version of the SDK wrapper and update your camera’s firmware via the web interface to avoid compatibility issues.

2. RGB to Temperature Conversion (Last Resort, Low Precision)

If you absolutely can’t get the SDK working, converting the RGB heatmap to temperature is possible—but it’s not accurate because the color mapping is non-linear and designed for visualization, not data extraction. Here’s how to do it if you have to:

Steps:

  1. Identify the camera’s color palette: Find out what pseudo-color map your camera uses (e.g., Iron Red, Rainbow) via the web interface under "Thermal Settings" > "Color Palette".
  2. Map RGB to intensity: Convert the RGB frame to a grayscale value that aligns with the palette’s intensity. For example, use the red channel for an Iron Red palette (red = hot, blue = cold).
  3. Linear temperature mapping: Use your known temperature range to convert intensity values to temperature:
    def rgb_to_temp(gray_value):
        temp_min = -20
        temp_max = 150
        return temp_min + (gray_value / 255) * (temp_max - temp_min)
    

Example Code Snippet:

import cv2

thermal = cv2.VideoCapture("rtsp://user:pass@ip:port/Streaming/channels/202/")

def mouse_callback(event, x, y, flags, param):
    if event == cv2.EVENT_LBUTTONDOWN:
        # Use red channel as intensity proxy for Iron Red palette
        pixel = frame[y][x]
        gray_value = pixel[2]
        temp = -20 + (gray_value / 255) * 170  # 170 = 150 - (-20)
        print(f"Estimated Temperature at ({x}, {y}): {temp:.2f}°C")

cv2.namedWindow('frame')
cv2.setMouseCallback('frame', mouse_callback)

while True:
    ret, frame = thermal.read()
    if not ret:
        break
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

thermal.release()
cv2.destroyAllWindows()

Warning: This method only gives rough estimates—don’t rely on it for precision tasks like critical temperature monitoring.

Troubleshooting Your Earlier Attempts

If the SDK didn’t work before, check these common pitfalls:

  • You used the standard network camera SDK instead of Hikvision’s thermal camera-specific SDK.
  • You skipped initializing the SDK correctly (the wrapper handles this, but raw C SDK requires calling NET_DVR_Init() first).
  • Your camera’s user account lacked permissions to access thermal data.

内容的提问来源于stack exchange,提问作者Amir Hossein Mobayen

火山引擎 最新活动