目标检测,我干了什么!

什么是卷积!important
https://www.cnblogs.com/alexanderkun/p/8149059.html
理解,文章里面有知乎链接,很好,卷积神经网络,卷积的工作原理,讲的都非常好
感恩!

https://zhuanlan.zhihu.com/p/66200671
今天看到这
pytouch实现yolov3

目标检测
https://blog.csdn.net/ft_sunshine/article/details/98342015#References_94
马哥给的好好看

https://pytorch.org/blog/
pytourch

https://mooc.study.163.com/learn/2001281004?tid=2001392030#/learn/content?type=detail&id=2001728688
尊敬的吴恩达老师教学视频

苏打水的杯子CSDN博客
https://blog.csdn.net/Fredric18/article/details/85057050
小狮子代码详解

目标检测优化方向:
训练好的SVM分类器保存为XML文件

https://blog.csdn.net/qq_25352981/article/details/52605768
利用hog+svm(梯度方向直方图和支持向量机)实现物体检测
这篇文章好像可以借鉴一下。关于svm 与 hog

裁剪图片
https://blog.csdn.net/Scythe666/article/details/88217594
保存数据到TXT
https://blog.csdn.net/qq_35826213/article/details/86627992
SVM+HOG:训练分类器生成.xml文件
https://blog.csdn.net/gojawee/article/details/72846232
利用Hog特征和SVM分类器进行行人检测
https://blog.csdn.net/carson2005/article/details/7841443
SVM+HOG:用初次训练的.xml分类器在负样本原图上检测生成HardExample样本
https://blog.csdn.net/GoJawee/article/details/72845508

https://blog.csdn.net/yongjiankuang/article/details/79808346
python+opencv实现hog+svm的训练

深度摄像头测蓝色摄像头的距离

import pyrealsense2 as rs
import numpy as np
import cv2
import cv2.aruco as aruco
import math
import time


def identify_colour(image, pose_mid, s, show_image=0):  # 这里pose_mid相当于一个承装物体信息的容器  pose_mid = [[0,0]]*10

    image2_hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

    LowerBlue = np.array([90, 100, 100])
    UpperBlue = np.array([130, 255, 255])
    mask = cv2.inRange(image2_hsv, LowerBlue, UpperBlue)
    image3_hsv = cv2.bitwise_and(image2_hsv, image2_hsv, mask=mask)
    image4_gry = image3_hsv[:, :, 0]

    blurred = cv2.blur(image4_gry, (9, 9))
    (_, thresh) = cv2.threshold(blurred, 90, 255, cv2.THRESH_BINARY)
    kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (25, 25))
    closed = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
    closed = cv2.erode(closed, None, iterations=4)
    closed = cv2.dilate(closed, None, iterations=4)
    # 系列操作猛如虎
    if show_image == 1:
        cv2.imshow('win6_bin', closed)

    contours, hier = cv2.findContours(closed, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    # 记住,这里是画出我们之前操作的效果图,长方形轮廓,经检测真的很好
    i = 0
    for c in contours:
        x, y, w, h = cv2.boundingRect(c)
        rect = cv2.minAreaRect(c)
        box = cv2.boxPoints(rect)
        box = np.int0(box)
        cv2.drawContours(image, [box], 0, (0, 0, 255), 3)
        pose_mid[i] = [(box[0][0] + box[2][0]) / 2, (box[0][1] + box[2][1]) / 2]
        w = math.sqrt((box[0][0] - box[1][0]) ** 2 + (box[0][1] - box[1][1]) ** 2)
        h = math.sqrt((box[0][0] - box[3][0]) ** 2 + (box[0][1] - box[3][1]) ** 2)
        s[i] = w * h

        s.sort(reverse=True)
        i = i + 1


# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)

# Start streaming
pipeline.start(config)
#cap = cv2.VideoCapture(0)
pose_mid = [[0, 0]] * 20
s = [0] * 10
while True:
    #ret, frame = cap.read()
    # Wait for a coherent pair of frames: depth and color
    frames = pipeline.wait_for_frames()

    depth_frame = frames.get_depth_frame()
    color_frame = frames.get_color_frame()
    color_image = np.asanyarray(color_frame.get_data())
    #cv2.namedWindow('ac', cv2.WINDOW_AUTOSIZE)
    #cv2.imshow("ac", color_image)
    cv2.waitKeyEx(100)
    if not depth_frame or not color_frame:
        continue
        # 识别image中的蓝色物体
    identify_colour(color_image, pose_mid, s, 1)  # 识别image中的蓝色物体



    """
    #color_image==>>image
    and now ,我的目标是找的corners,还有蓝色方框
    我们现在有什么,我们现在可以做些什么
    事实上,通过图像移植,我们已经可以获得蓝色物体
    : # 识别image中的蓝色物体
       # pose_mid:蓝色物体的像素坐标
       # s:蓝色物体的体积?----面积吧
    因此,我们可以实现蓝色物体框处图像
    获得蓝色物体坐标++++
    这就是问题所在,我们的cv2.findContours()返回的值是蓝色物体坐标,蓝色物体的高与宽,但是我们之所以融合是想要具体物体的具体Z,从而实现,根据
    """
    """
    gray = cv2.cvtColor(color_image, cv2.COLOR_BGR2GRAY)
    aruco_dict = aruco.Dictionary_get(aruco.DICT_5X5_250)
    parameters = aruco.DetectorParameters_create()
    # print(parameters)

    corners, ids, rejectedImgPoints = aruco.detectMarkers(gray, aruco_dict, parameters=parameters)
    """
   # print(corners)

    # get intrinsic of color image
    color_intrinsics = color_frame.profile.as_video_stream_profile().intrinsics
    if 1 != 0:
        """
        知道我为什么要这样做吗?因为,我入坑了!
        麻烦瞪大眼睛看一下type(point[0])是什么类型,<class numpy.float32>!!!!!!一个数字怎么可能有那么多的类型花样呢?
        日,费劲,加油
        但是
        作者在2019/10/17/2:03分猝死!
        """
        x=pose_mid[0][0]
        y=pose_mid[0][1]
        point=np.array([x,y],dtype=np.float32)
        depth = depth_frame.get_distance(point[0], point[1])
        point = np.append(point, depth)

        print(point)
        if depth != 0:
            global center
            x = point[0]
            y = point[1]
            z = point[2]
            ## see rs2 document:
            ## https://github.com/IntelRealSense/librealsense/wiki/Projection-in-RealSense-SDK-2.0#point-coordinates
            ## and example: https://github.com/IntelRealSense/librealsense/wiki/Projection-in-RealSense-SDK-2.0#point-coordinates
            x, y, z = rs.rs2_deproject_pixel_to_point(color_intrinsics, [x, y], z)
            center = [x, y, z]
            print(center)
            #color_image = aruco.drawDetectedMarkers(color_image, corners)
    #cv2.imshow('frame', gray)
    cv2.imshow('corners',color_image)


深度摄像头取距离
二维码

import pyrealsense2 as rs
import numpy as np
import cv2
import cv2.aruco as aruco

# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)

# Start streaming
pipeline.start(config)
#cap = cv2.VideoCapture(0)
while True:
    #ret, frame = cap.read()
    # Wait for a coherent pair of frames: depth and color
    frames = pipeline.wait_for_frames()

    depth_frame = frames.get_depth_frame()
    color_frame = frames.get_color_frame()
    color_image = np.asanyarray(color_frame.get_data())
    #cv2.namedWindow('ac', cv2.WINDOW_AUTOSIZE)
    #cv2.imshow("ac", color_image)
    cv2.waitKeyEx(100)
    if not depth_frame or not color_frame:
        continue

    gray = cv2.cvtColor(color_image, cv2.COLOR_BGR2GRAY)
    aruco_dict = aruco.Dictionary_get(aruco.DICT_5X5_250)
    parameters = aruco.DetectorParameters_create()
    # print(parameters)

    corners, ids, rejectedImgPoints = aruco.detectMarkers(gray, aruco_dict, parameters=parameters)
    print("this is corners")
    print(corners)

    # get intrinsic of color image
    color_intrinsics = color_frame.profile.as_video_stream_profile().intrinsics

    if len(corners) != 0:
        print(corners[0][0])
        print("this is my style:")
        print(type(corners[0][0]))
        point = np.average(corners[0][0], axis=0)
        print("this is point")
        print(point)
        depth = depth_frame.get_distance(point[0], point[1])
        print(type(point[0]))
        print("the point[0] is that :")
        print(point[0])
        print(point[1])
        point = np.append(point, depth)
        print("this is the depth that running in the table")
        print(point)
        if depth != 0:
            global center
            x = point[0]
            y = point[1]
            z = point[2]
            ## see rs2 document:
            ## https://github.com/IntelRealSense/librealsense/wiki/Projection-in-RealSense-SDK-2.0#point-coordinates
            ## and example: https://github.com/IntelRealSense/librealsense/wiki/Projection-in-RealSense-SDK-2.0#point-coordinates
            x, y, z = rs.rs2_deproject_pixel_to_point(color_intrinsics, [x, y], z)
            center = [x, y, z]
            print(center)
            color_image = aruco.drawDetectedMarkers(color_image, corners)
            print('Ok')
    #cv2.imshow('frame', gray)
    cv2.imshow('corners',color_image)


普通摄像头测蓝色物体距离

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Copyright 2019 The UFACTORY Inc. All Rights Reserved.
#
# Software License Agreement (BSD License)
#
# Author: Jimy Zhang <jimy.zhang@ufactory.cc> <jimy92@163.com>
# =============================================================================

import cv2
import numpy as np
import math
import time

class CameraDriver(object):
  def __init__(self, video_port):
    self.cameraCapture = cv2.VideoCapture(video_port)
    self.xy2=[1,1]
    self.state = 0

  def close(self):
    cv2.destroyAllWindows()

  def get_image(self):#获取图片
    cv2.waitKey(1)
    success, image_src = self.cameraCapture.read()
    if success:
      return image_src
    else:
      print("ERROR: cameraCapture.read()")
      self.state = -1

  # 识别image中的蓝色物体
  # pose_mid:蓝色物体的像素坐标
  # s:蓝色物体的体积?----面积吧
  # show_image:1->显示过程图片;0->不显示过程图片
  def identify_colour(self, image, pose_mid, s, show_image=0):#这里pose_mid相当于一个承装物体信息的容器  pose_mid = [[0,0]]*10
    if self.state == -1:
      return

    image2_hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

    LowerBlue = np.array([90, 100, 100])
    UpperBlue = np.array([130, 255, 255])
    mask = cv2.inRange(image2_hsv, LowerBlue, UpperBlue)
    image3_hsv = cv2.bitwise_and(image2_hsv, image2_hsv, mask=mask)
    image4_gry = image3_hsv[:,:,0]

    blurred = cv2.blur(image4_gry, (9, 9))
    (_, thresh) = cv2.threshold(blurred, 90, 255, cv2.THRESH_BINARY)
    kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (25, 25))
    closed = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
    closed = cv2.erode(closed, None, iterations=4)
    closed = cv2.dilate(closed, None, iterations=4)
    #系列操作猛如虎
    if show_image == 1:
      cv2.imshow('win6_bin', closed)

    contours, hier = cv2.findContours(closed, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    #记住,这里是画出我们之前操作的效果图,长方形轮廓,经检测真的很好
    i = 0
    for c in contours:
      x, y, w, h = cv2.boundingRect(c)
      rect = cv2.minAreaRect(c)
      box = cv2.boxPoints(rect)
      box =np.int0(box)
      cv2.drawContours(image, [box], 0, (0, 0, 255), 3)

      pose_mid[i] = [(box[0][0] + box[2][0])/2, (box[0][1] + box[2][1])/2]
      w = math.sqrt((box[0][0] - box[1][0])**2 + (box[0][1] - box[1][1])**2)
      h = math.sqrt((box[0][0] - box[3][0])**2 + (box[0][1] - box[3][1])**2)
      s[i] = w * h
      s.sort(reverse=True)
      i = i + 1

    if show_image == 1:
      cv2.imshow("Image", image)

连载++主函数

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Copyright 2019 The UFACTORY Inc. All Rights Reserved.
#
# Software License Agreement (BSD License)
#
# Author: Jimy Zhang <jimy.zhang@ufactory.cc> <jimy92@163.com>
# =============================================================================


#import rospy
#from std_msgs.msg import String
from camera_driver import CameraDriver

def main():
  #实例化CameraDriver,参数0 (调用/dev/video0摄像头)
  camera = CameraDriver(0)
  pose_mid = [[0,0]]*10
  s = [0]*10
  while(1):
    image = camera.get_image()  # 获取一帧图片

    # 识别image中的蓝色物体
    camera.identify_colour(image, pose_mid, s, 1) # 识别image中的蓝色物体
    # 打印蓝色物体的坐标信息
    print(pose_mid)
    # 打印蓝色物品的面积
    print(s)
    print(' ')

if __name__ == '__main__':
  main()

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值