dai3372757
dai3372757
采纳率0%
2019-03-24 05:24 阅读 1.6k

Jetson TX2 GPU占用不正常

80

我并没有在程序中使用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条回答 默认 最新

  • caozhy 从今以后生命中的每一秒都属于我爱的人 2019-03-24 09:09

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

    点赞 1 评论 复制链接分享

相关推荐