# how to use IR camera +raspberrypi 3b+ in python:

1.connect the camera module:    shut down the respberrypi power,connect the camera

2.open the ir camera:                use python IDE

目录

Introduction

What you will need

Raspberry Pi computer with a Camera Module port

Raspberry Pi Camera Module

Connect the Camera Module

How to control the Camera Module via the command line

How to control the Camera Module with Python code

Recording video with Python code

How to change the image settings and add image effects

Set the image resolution

Add text to your image

Change the look of the added text

Change the brightness of the preview

Change the contrast of the preview


Introduction

Learn how to connect the Raspberry Pi Camera Module to your Raspberry Pi and take pictures, record video, and apply image effects.

What you will need

Raspberry Pi computer with a Camera Module port

All current models of Raspberry Pi have a port for connecting the Camera Module.

Note: If you want to use a Raspberry Pi Zero, you need a Camera Module ribbon cable that fits the Raspberry Pi Zero’s smaller Camera Module port.

Raspberry Pi Camera Module

Connect the Camera Module

Ensure your Raspberry Pi is turned off.

  1. Locate the Camera Module port
  2. Gently pull up on the edges of the port’s plastic clip
  3. Insert the Camera Module ribbon cable; make sure the cable is the right way round
  4. Push the plastic clip back into place
  • Start up your Raspberry Pi.

  • Go to the main menu and open the Raspberry Pi Configuration tool.

  • Select the Interfaces tab and ensure that the camera is enabled:

  • Reboot your Raspberry Pi.

How to control the Camera Module via the command line

Now your Camera Module is connected and the software is enabled, try out the command line tools raspistill and raspivid.

  • Open a terminal window by clicking the black monitor icon in the taskbar:
  • Type in the following command to take a still picture and save it to the Desktop:
raspistill -o Desktop/image.jpg

  • Press Enter to run the command.

When the command runs, you can see the camera preview open for five seconds before a still picture is taken.

  • Look for the picture file icon on the Desktop, and double-click the file icon to open the picture.

By adding different options, you can set the size and look of the image the raspistill command takes.

  • For example, add -h and -w to change the height and width of the image:
raspistill -o Desktop/image-small.jpg -w 640 -h 480
  • Now record a video with the Camera Module by using the following raspivid command:
raspivid -o Desktop/video.h264
  • In order to play the video file, double-click the video.h264 file icon on the Desktop to open it in VLC Media Player.

How to control the Camera Module with Python code

The Python picamera library allows you to control your Camera Module and create amazing projects.

You should see the camera preview open for five seconds, and then a still picture should be captured. As the picture is being taken, you can see the preview briefly adjust to a different resolution.

Your new image should be saved to the Desktop.

The camera should take one picture every five seconds. Once the fifth picture is taken, the preview closes.

Your Raspberry Pi should open a preview, record 5 seconds of video, and then close the preview.

  • Open a Python 3 editor, such as Thonny Python IDE:

  • Open a new file and save it as camera.py.

    Note: it’s important that you never save the file as picamera.py.

  • Enter the following code:

    from picamera import PiCamera
    from time import sleepcamera = PiCamera()camera.start_preview()
    sleep(5)
    camera.stop_preview()
  • Save and run your program. The camera preview should be shown for five seconds and then close again.

  • If your preview is upside-down, you can rotate it by 180 degrees with the following code:

    camera = PiCamera()
    camera.rotation = 180

    You can rotate the image by 90180, or 270 degrees. To reset the image, set rotation to 0 degrees.

  • Make the camera preview see-through by setting an alpha level:

    camera.start_preview(alpha=200)

    The alpha value can be any number between 0 and 255.

  • It’s best to make the preview slightly see-through so you can see whether errors occur in your program while the preview is on.

  • Now use the Camera Module and Python to take some still pictures.

  • Amend your code to add a camera.capture() line:

    camera.start_preview()
    sleep(5)
    camera.capture('/home/pi/Desktop/image.jpg')
    camera.stop_preview()

    Note: it’s important to sleep for at least two seconds before capturing an image, because this gives the camera’s sensor time to sense the light levels.

  • Run the code.

  • Now add a loop to take five pictures in a row:

    camera.start_preview()
    for i in range(5):sleep(5)camera.capture('/home/pi/Desktop/image%s.jpg' % i)
    camera.stop_preview()

    The variable i counts how many times the loop has run, from 0 to 4. Therefore, the images get saved as image0.jpgimage1.jpg, and so on.

  • Look at your Desktop to find the five new pictures.
    • Run the code again and hold the Camera Module in position.

    • Recording video with Python code

      Now record a video!

    • Amend your code to remove capture() and instead add start_recording() and stop_recording()

      Your code should look like this now:

      camera.start_preview()
      camera.start_recording('/home/pi/Desktop/video.h264')
      sleep(5)
      camera.stop_recording()
      camera.stop_preview()
    • Run the code.

How to change the image settings and add image effects

The Python picamera software provides a number of effects and configurations to change how your images look.

Note: some settings only affect the preview and not the captured image, some affect only the captured image, and many others affect both.

Set the image resolution

You can change the resolution of the image that the Camera Module takes.

By default, the image resolution is set to the resolution of your monitor. The maximum resolution is 2592×1944 for still photos, and 1920×1080 for video recording.

Use the following code to set the resolution to maximum and take a picture.

Note: you also need to set the frame rate to 15 to enable this maximum resolution.

camera.resolution = (2592, 1944)
camera.framerate = 15
camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/max.jpg')
camera.stop_preview()

The minimum resolution is 64×64.

Add text to your image

You can add text to your image using the command annotate_text.

Change the look of the added text

It’s also possible to change the text colour.

Change the brightness of the preview

You can change how bright the preview appears. The default brightness is 50, and you can set it to any value between 0 and 100.

Change the contrast of the preview

Similarly to the preview brightness, you can change the contrast of the preview.

The default effect is none.

本篇文章转载自:https://projects.raspberrypi.org/en/projects/getting-started-with-picamera

更多请关注“树莓派官网”:https://projects.raspberrypi.org/en

  • Try taking a picture with the minimum resolution.
  • Run this code to try it:

    camera.start_preview()
    camera.annotate_text = "Hello world!"
    sleep(5)
    camera.capture('/home/pi/Desktop/text.jpg')
    camera.stop_preview()
  • Set the text size with the following code:

    camera.annotate_text_size = 50

    You can set the text size to anything between 6 to 160. The default size is 32.

  • First of all, add Color to your import line at the top of the program:

    from picamera import PiCamera, Color
  • Then below the import line, amend the rest of your code so it looks like this:

    camera.start_preview()
    camera.annotate_background = Color('blue')
    camera.annotate_foreground = Color('yellow')
    camera.annotate_text = " Hello world "
    sleep(5)
    camera.stop_preview()
  • Run the following code to try this out:

    camera.start_preview()
    camera.brightness = 70
    sleep(5)
    camera.capture('/home/pi/Desktop/bright.jpg')
    camera.stop_preview()
  • The following loop adjusts the brightness and also adds text to display the current brightness level:

    camera.start_preview()
    for i in range(100):camera.annotate_text = "Brightness: %s" % icamera.brightness = isleep(0.1)
    camera.stop_preview()
  • Run the following code to try this out:

    camera.start_preview()
    for i in range(100):camera.annotate_text = "Contrast: %s" % icamera.contrast = isleep(0.1)
    camera.stop_preview()
  • Pick an image effect and try it out:
  • camera.start_preview()
    camera.image_effect = 'colorswap'
    sleep(5)
    camera.capture('/home/pi/Desktop/colorswap.jpg')
    camera.stop_preview()
  • Run this code to loop over all the image effects with camera.IMAGE_EFFECTS:

    camera.start_preview()
    for effect in camera.IMAGE_EFFECTS:camera.image_effect = effectcamera.annotate_text = "Effect: %s" % effectsleep(5)
    camera.stop_preview()

[树莓派] : 如何用树莓派利用摄像头进行简单的人脸识别【how to use IR camera +raspberrypi 3b+ in python】相关推荐

  1. 史上最简单的人脸识别项目登上GitHub趋势榜

    来源 | GitHub Trending整理 | Freesia译者 | TommyZihao出品 | AI科技大本营(ID: rgznai100) 导读:近日,一个名为 face_recogniti ...

  2. 详解深度学习之经典网络:AlexNet(2012) 并利用该网络架构实现人脸识别

    @[TOC](详解深度学习之经典网络:AlexNet(2012) 并利用该网络架构实现人脸识别**) 近来闲来无事,翻出了搁置已久的轻薄版电脑,望着积满灰尘的显示屏,觉得有愧于老师的尊尊教导,心中叹息 ...

  3. Qt 使用摄像头通过openCV进行人脸识别

    Qt 使用摄像头通过openCV进行人脸识别 资源下载 环境信息 1. 下载cpenCV和opencv_contrib源码 2. 安装CMake 3. 编译openCV 开始编译 4. 新建工程调用o ...

  4. 用Python实现简单的人脸识别,10分钟(附源码)

    前言 今天,我们用Python实现简单的人脸识别技术! Python里,简单的人脸识别有很多种方法可以实现,依赖于python胶水语言的特性,我们通过调用包可以快速准确的达成这一目的.这里介绍的是准确 ...

  5. 用Python几行代码实现简单的人脸识别,10分钟完成(附源码)

    前言 今天,我们用Python实现简单的人脸识别技术! Python里,简单的人脸识别有很多种方法可以实现,依赖于python胶水语言的特性,我们通过调用包可以快速准确的达成这一目的.这里介绍的是准确 ...

  6. 10分钟手把手教你运用Python实现简单的人脸识别

    欲直接下载代码文件,关注我们的公众号哦!查看历史消息即可! 前言:让我的电脑认识我 我的电脑只有认识我,才配称之为我的电脑! 今天,我们用Python实现高大上的人脸识别技术! Python里,简单的 ...

  7. Python简单实现人脸识别检测, 对照片进行评分

    大家好,今天和大家说说如何用Python简单实现人脸识别检测, 对照片进行排名,看看自己有多漂亮. [开发环境]: Python 3.8 Pycharm 2021.2 [模块使用]: requests ...

  8. 吗咿呀嘿-用js来搞个简单的人脸识别

    缘起 "蚂蚁呀嘿,蚂蚁呀呼,蚂蚁呀哈" 相信最近好多人的朋友圈或者抖音都被类似视频刷过屏! 类似的效果最早是在2020年初,那个时候大家应该还都记得,几乎所有的人都因为疫情原因被迫 ...

  9. vue 使用人脸识别_使用Vue.js和Kairos构建简单的人脸识别应用

    vue 使用人脸识别 Face Detection and Recognition have become an increasingly popular topic these days. It's ...

最新文章

  1. 使用Typescript的巧妙React上下文技巧-不是Redux
  2. Mac svn使用学习-2-服务端
  3. c4d fbx大小_【第77期】双节来临,全球顶级C4D商用模型助你一臂之力!
  4. USTC English Club Note20171012(4)
  5. 如何防止插入删除表造成的数据库死锁
  6. tiny4412 SDK1312B LED驱动
  7. php is_dir 判断是否存在这目录
  8. 从GlassFish 3.x扩展到WebLogic 12c Server
  9. python 常用模块函数_python函数和常用模块(三),Day5
  10. 阿里云数据盘分区并挂载
  11. 使用SAXReader以XML方式解析excel
  12. 利用excel搭建动态图表
  13. pytorch实现straight-through estimator(STE)
  14. 远程桌面之客户端连接(MAC远程Windows桌面)
  15. u盘内存怎么测试软件,U盘下的内存检测软件
  16. lisp+等高线点线矛盾检查_基于AutoCAD平台地形图高程点与等高线点线矛盾检测方法研究与实现...
  17. 基于android音乐播放器的设计
  18. scratch词语接龙 电子学会图形化编程scratch等级考试四级真题和答案解析2021-6
  19. python怎么计算圆_python根据圆的参数方程求圆上任意一点的坐标
  20. java 单例模式双重检索_单例模式:为什么要双重检测

热门文章

  1. objective-c 关键字和概念
  2. cratedb导入json文件
  3. 007-配置IP和DNS
  4. 基于Redis的限流系统的设计
  5. [转载]Docker的安装配置及使用详解
  6. CentOS平滑更新nginx版本
  7. silverlight 自定义资源整理(待后续补充)
  8. T SQL + 正则表达式
  9. C#中的表达式与运算符
  10. c++ 原子操作 赋值_Volatile深度剖析-原子性