当前位置: 首页 > news >正文

代替Spinnaker 的 POINTGREY工业级相机 FLIR相机 Python编程案例

SpinnakerSDK_FULL_4.0.0.116_x64 是一个用于FLIR相机的SDK,主要用于图像采集和处理。Spinnaker SDK主要提供C++接口,无法直接应用在python环境。本文则基于Pycharm2019+python3.7的环境下,调用opencv,EasySpin,PySpin,的库实现POINTGREY工业级相机的开发。

1.Spinnaker SDK
首先,需要去Spinnaker SDK | Teledyne FLIR官网上下载相应的SDK

选择WINDOWS,解压得到一下文件

 下载Latest Spinnaker Full SDK中的SDK

下载完成后打开SpinView查看是否有用(之前想做FlyCapture但是FlyCapture打不开)

2.Pycharm+Python的环境(可自行配置)
3.EasyPySpin库
        在查找相关资料的时候在git-hub上找到了一个库,该库能够实现用opencv的方式调用Spinnaker的摄像头方便后续的图像处理。
elerac/EasyPySpin: cv2.VideoCapture like wrapper for FLIR Spinnaker SDK (github.com)
https://github.com/elerac/EasyPySpin

        相关使用说明在其中,在Pycharm中能够通过Seting搜索

         进行下载

4.PySpin
        如果只调用EasyPySpin的库直接运行程序,会提示缺少PySpin的库函数因此需要安装PySpin库,该库不能通过setting进行安装需要

利用 Latest Python Spinnaker中的whl文件进行安装

选择对应版本的Spin(其中cp是对应python的版本)

然后安装whl的文件

使用pip install 文件名.whl 

5.运行Example程序
"""A simple example of capturing and displaying an image
"""
import EasyPySpin
import cv2
def main():
    cap = EasyPySpin.VideoCapture(0)
 
    if not cap.isOpened():
        print("Camera can't open\nexit")
        return -1
 
    cap.set(cv2.CAP_PROP_EXPOSURE, -1)  # -1 sets exposure_time to auto
    cap.set(cv2.CAP_PROP_GAIN, -1)  # -1 sets gain to auto
 
    while True:
        ret, frame = cap.read()
        # frame = cv2.cvtColor(frame, cv2.COLOR_BayerBG2BGR)  # for RGB camera demosaicing
 
        img_show = cv2.resize(frame, None, fx=0.25, fy=0.25)
        cv2.imshow("press q to quit", img_show)
        key = cv2.waitKey(30)
        if key == ord("q"):
            break
 
    cap.release()
    cv2.destroyAllWindows()
 
 
if __name__ == "__main__":
    main()

结果如下:

"""A simple example of capturing and displaying an image
"""
import EasyPySpin
import cv2
import numpy as np
import math
import copy
 
 
 
def main():
    cap = EasyPySpin.VideoCapture(0)
 
    if not cap.isOpened():
        print("Camera can't open\nexit")
        return -1
    frameNum = 0
 
    cap.set(cv2.CAP_PROP_EXPOSURE, -1)  # -1 sets exposure_time to auto 自动曝光时间
    cap.set(cv2.CAP_PROP_GAIN, -1)  # -1 sets gain to auto              自动增益
 
    while True:
        ret, frame = cap.read()
        # frame = cv2.cvtColor(frame, cv2.COLOR_BayerBG2BGR)  # for RGB camera demosaicing
        frameNum += 1
        if ret == True:
            tempframe = frame
            if (frameNum == 1):
                previousframe = frame
                print(111)
            if (frameNum >= 2):
                currentframe = tempframe
                currentframe = cv2.absdiff(currentframe, previousframe) #帧差法图
 
                median = cv2.medianBlur(currentframe, 3)  #中值滤波
 
                ret, threshold_frame = cv2.threshold(currentframe, 20, 255, cv2.THRESH_BINARY)
                gauss_image = cv2.GaussianBlur(threshold_frame, (3 ,3), 0)
                contours, hierarchy = cv2.findContours(threshold_frame, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
 
                yuantu_show = cv2.resize(frame, None, fx=0.25, fy=0.25)
                intital_show = cv2.resize(frame, None, fx=0.25, fy=0.25)
                img_show = cv2.resize(gauss_image, None, fx=0.25, fy=0.25)
 
                # 画出矩形轮廓
                for i in range(0, len(contours)):
                    x, y, w, h = cv2.boundingRect(contours[i])
                    cv2.rectangle(yuantu_show, (x, y), (x + w, y + h), (255, 255, 0), 2)
 
 
 
 
                #图片显示
                cv2.imshow('yuantu', intital_show)
                cv2.imshow('lunkou', yuantu_show)  # 原图显示
                #cv2.imshow('tuxiangchuli', img_show) # 经过高斯滤波之后
                #cv2.imshow('lvbo', median)
 
                #时间延迟
                key = cv2.waitKey(30)
 
                #按q退出
                if key == ord("q"):
                    break
    #释放内存
    cap.release()
    cv2.destroyAllWindows()
 
 
if __name__ == "__main__":
    main()

利用帧差法进行视频的图像处理

 

http://www.lryc.cn/news/488226.html

相关文章:

  • 网络篇12 | SSH2协议应用,禁SFTP子模式实现文件传输
  • MetaGPT实现多动作Agent
  • docker更新镜像源
  • TSmaster Trace 窗口
  • 【Python模拟websocket登陆-拆包封包】
  • 速盾:海外服务器使用CDN加速有什么好处?
  • windows系统中实现对于appium的依赖搭建
  • 使用MATLAB进行字符串处理
  • Sourcetree登录GitLab账号
  • Linux进阶:软件安装、网络操作、端口、进程等
  • 光猫、路由器、交换机之连接使用(Connection and Usage of Optical Cats, Routers, and Switches)
  • 2025蓝桥杯(单片机)备赛--扩展外设之超声波测距原理与应用(十一)
  • 分布式数据库中间件可以用在哪些场景呢
  • MyBatis-Plus分页插件IPage用法
  • 使用MATLAB进行遗传算法设计
  • mindtorch study
  • java八股-SpringCloud微服务-Eureka理论
  • 2024信创数据库TOP30之蚂蚁集团OceanBase
  • 查找redis数据库的路径
  • DrugLLM——利用大规模语言模型通过 Few-Shot 生成生物制药小分子
  • 【蓝桥杯C/C++】翻转游戏:多种实现与解法解析
  • 【AI系统】核心计算之矩阵乘
  • Vue.js 自定义指令:从零开始创建自己的指令
  • 策略模式
  • 性能优化--CPU微架构
  • 在 Sanic 框架中实现高效内存缓存的多种方法
  • Mac 环境变量配置基础教程
  • Qt如何屏蔽工具栏(QToolBar)自动折叠功能
  • 【数据分享】中国统计摘要(1978-2024)
  • unity运行状态下移动、旋转、缩放控制模型