前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >用Jetson NANO做个智能电视机,这个操作有点意思

用Jetson NANO做个智能电视机,这个操作有点意思

作者头像
GPUS Lady
发布2020-10-28 17:27:46
1.3K0
发布2020-10-28 17:27:46
举报
文章被收录于专栏:GPUS开发者

印度有个小哥哥用Jetson NANO做了一个智能电视机,怎么个智能法儿呢?

各位请看——

走到电视机面前,电视就正常播放,离开电视机,电视就暂停 http://mpvideo.qpic.cn/0bf2gmfk4aakfyab7h4p4rpvum6dvyzqvlqa.f10003.mp4?dis_k=f0492e11741e782ab3230f4b22ef9290&dis_t=1603877224&vid=wxv_1560362929106010113&format_id=10003

是不是很有魔性的感觉...我居然对着这视频看了好几遍...

好了,让我们看看他是怎么实现的。

首先你得有一台索尼Bravia电视x80G,一个Jetson NANO,和一个USB摄像头

这里需要用到“IRCC-IP”协议,这是指“互联网协议的红外兼容控制”。它可以通过IP发送红外遥控指令码。

整个功能实现其实很简单:

  • 该项目使用Jetson Nano和Jetpack sdk检测房间中的人
  • Jetson Nano会通过IRCCIP Api指示索尼电视根据房间人员出现情况暂停/播放内容,这样您就不会错过任何内容!

小哥哥提供的代码:

代码语言:javascript
复制
#!/usr/bin/python
#
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#

import jetson.inference
import jetson.utils
import requests
import time
import argparse
import sys

def rem_pause():

    url = "http://192.168.1.100/sony/ircc"

    payload = "<s:Envelope\r\n    xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"\r\n    s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n    <s:Body>\r\n        <u:X_SendIRCC xmlns:u=\"urn:schemas-sony-com:service:IRCC:1\">\r\n            <IRCCCode>AAAAAgAAAJcAAAAZAw==</IRCCCode>\r\n        </u:X_SendIRCC>\r\n    </s:Body>\r\n</s:Envelope>"
    headers = {
    'Accept': '*/*',
    'Content-Type': 'text/xml',
    'SOAPACTION': '"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"',
    'X-Auth-PSK': '1234'
    }

    response = requests.request("POST", url, headers=headers, data = payload)

    print(response.text.encode('utf8'))

def rem_play():

    url = "http://192.168.1.100/sony/ircc"

    payload = "<s:Envelope\r\n    xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"\r\n    s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n    <s:Body>\r\n        <u:X_SendIRCC xmlns:u=\"urn:schemas-sony-com:service:IRCC:1\">\r\n            <IRCCCode>AAAAAgAAAJcAAAAaAw==</IRCCCode>\r\n        </u:X_SendIRCC>\r\n    </s:Body>\r\n</s:Envelope>"
    headers = {
    'Accept': '*/*',
    'Content-Type': 'text/xml',
    'SOAPACTION': '"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"',
    'X-Auth-PSK': '1234'
    }

    response = requests.request("POST", url, headers=headers, data = payload)

    print(response.text.encode('utf8'))


# parse the command line
parser = argparse.ArgumentParser(description="Locate objects in a live camera stream using an object detection DNN.", 
               formatter_class=argparse.RawTextHelpFormatter, epilog=jetson.inference.detectNet.Usage())

parser.add_argument("--network", type=str, default="ssd-mobilenet-v2", help="pre-trained model to load (see below for options)")
parser.add_argument("--overlay", type=str, default="box,labels,conf", help="detection overlay flags (e.g. --overlay=box,labels,conf)\nvalid combinations are:  'box', 'labels', 'conf', 'none'")
parser.add_argument("--threshold", type=float, default=0.5, help="minimum detection threshold to use") 
parser.add_argument("--camera", type=str, default="0", help="index of the MIPI CSI camera to use (e.g. CSI camera 0)\nor for VL42 cameras, the /dev/video device to use.\nby default, MIPI CSI camera 0 will be used.")
parser.add_argument("--width", type=int, default=1280, help="desired width of camera stream (default is 1280 pixels)")
parser.add_argument("--height", type=int, default=720, help="desired height of camera stream (default is 720 pixels)")

try:
  opt = parser.parse_known_args()[0]
except:
  print("")
  parser.print_help()
  sys.exit(0)

# load the object detection network
net = jetson.inference.detectNet(opt.network, sys.argv, opt.threshold)

# create the camera and display
camera = jetson.utils.gstCamera(opt.width, opt.height, opt.camera)
display = jetson.utils.glDisplay()
pausepl=0
# process frames until user exits
while display.IsOpen():
  # capture the image
  img, width, height = camera.CaptureRGBA()

  # detect objects in the image (with overlay)
  detections = net.Detect(img, width, height, opt.overlay)

  # print the detections
  print("detected {:d} objects in image".format(len(detections)))

  for detection in detections:
    print(detection)

  if len(detections)>0 and pausepl==1:
    rem_play()
    pausepl=0
    time.sleep(1)

  if(len(detections)==0 and pausepl==0):
    rem_pause()
    pausepl=1
    time.sleep(1)

  # render the image
  display.RenderOnce(img, width, height)

  # update the title bar
  display.SetTitle("{:s} | Network {:.0f} FPS".format(opt.network, net.GetNetworkFPS()))
  #display.SetTitle(list.count(detections))
  # print out performance info
  net.PrintProfilerTimes()

(左右滑动可以看见完整代码)

这个代码的前面的主要部分, 是通过索尼的API, 进行电视控制。后面的部分,则主要是通过detectNet进行检测,因为是用的jetson.inference.detectNet,所以自己几乎不用写代码,同时用的jetson.utils.gstCamera返回的camera对象, 进行RGBA的一帧的捕获.

综合起来应当是, 调用摄像头输入, 检测对象, 如果检测到,print输出, 同时调用电视的API, 静帧, 暂停在捕获的这一瞬间, 然后1秒后继续播放.

是不是很有意思?我觉得可以好好思考一下小哥哥的这个思路,并没有复杂的算法,但也实现了一个人工智能的功能,我甚至觉得新出来的Jetson NANO 2GB也是可以实现的。大家不妨试一试。

这个项目介绍可以访问:https://www.hackster.io/hackfire132/b-smarter-tv-11cb23

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-10-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 GPUS开发者 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档