Jetson TX2 GPU占用不正常 80C

我并没有在程序中使用GPU运算(大概?),但是GPU占用非常高,请问各位大佬指点迷津。。。

代码是实际运算的部分

#!/usr/bin/env python

import sys
import time
import numpy as np
import cv2


ROIPt = []
cropping = False
flag=0

def mouse_choose(event, x, y, flags, param):

        global ROIPt, cropping, flag

        if event == cv2.EVENT_LBUTTONDOWN:
                ROIPt = [(x, y)]
                cropping = True

        elif event == cv2.EVENT_LBUTTONUP:

                ROIPt.append((x, y))
                cropping = False


                cv2.rectangle(frame, ROIPt[0], ROIPt[1], (0, 255, 0), 1)
                cv2.imshow("frame", frame)
                flag=1

cap = cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink")

if not cap.isOpened():
    print("not capture")
    exit()

ret,frame = cap.read()
cv2.namedWindow('frame')
cv2.setMouseCallback("frame", mouse_choose)

while 1:
    while ret:
        start = time.time()
        cv2.imshow('frame',frame)
        end = time.time()
        print("imshow:",end-start)
        start = time.time()
        ret,frame = cap.read()
        end = time.time()
        print("load_matrix:",end-start)
        key = cv2.waitKey(1) & 0xFF

        if flag==1:
                break


    if len(ROIPt) == 2:
        roi = frame[ROIPt[0][1]:ROIPt[1][1], ROIPt[0][0]:ROIPt[1][0]]
        cv2.imshow("ROI", roi)
        start = time.time()
        roi_gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
        end = time.time()
        print("roi_gray:",end-start)
        start = time.time()
        sobel_x=cv2.Sobel(roi_gray,-1,1,0,ksize=3)
        end = time.time()
        print("Sobel 1:",end-start)
        start = time.time()
        sobel_y=cv2.Sobel(roi_gray,-1,0,1,ksize=3)
        end = time.time()
        print("Sobel 2:",end-start)
        start = time.time()
        sobel_result = cv2.addWeighted(sobel_x,1,sobel_y,1,0)
        end = time.time()
        print("add two matrix:",end-start)
        start = time.time()
        _,threshold_result=cv2.threshold(sobel_result,50,255,cv2.THRESH_TOZERO);
        end = time.time()
        print("threshold:",end-start)

        start = time.time()
        sobel_value=cv2.sumElems(threshold_result)
        end = time.time()
        print("sum the whole matrix:",end-start)
        start = time.time()
        output_value=sobel_value[0]//10000
        end = time.time()
        print("division:",end-start)

        print(output_value)
cap.release()
cv2.destroyAllWindows()


v
如果用鼠标在视频上选择了700x700大小的区域进行运算GPU占用达到60~70
图片说明

这是相关运算进行的时间
图片说明

1个回答

正常的,opencv调用gpu编码,就是有比较大的负载。和你视频分辨率高低数据量无关。

dai3372757
dai3372757 大佬,请问这算不算使用GPU进行了矩阵运算呀,还有我找不到能说明opencv调用了GPU的文档T_T
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问