Skip to content

Raspberry Pi 2B使用USB Camera获取图片,OpenCV分析图片相识度,决定Relay是否触发开关。

Notifications You must be signed in to change notification settings

ZengjfOS/CameraRelay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Camera Relay

在树莓派上安装USB Camera,通过GPIO口控制设备电源,在电源上点一定时间后,对设备进行拍照。

Ctrl+c停止程序运行。

一、参考文档:

二、USAGE

2.1 Help

usage: CameraRelay.py [-h] -on ON -off OFF -cap CAP

Camera Control Relay.

optional arguments:
  -h, --help  show this help message and exit
  -on ON      Power On Duty(s)
  -off OFF    Power Off Duty(s)
  -cap CAP    Camera Capture Image Delay After Power On(s)

Example: ./CameraRelay.py -on 4 -off 2 -cap 1

2.2 Example

./CameraRelay.py -on 4 -off 2 -cap 1 
  • System Power On: 4(s)
  • System Power Off: 2(s)
  • USB Camera capture a image after Power On: 1(s)

2.3 CMD Output Example

root@raspberrypi:/home/pi/CameraRelay# ./CameraRelay.py -on 4 -off 2 -cap 1
Namespace(cap='1', off='2', on='4')
 powerOnTime: 4.0.
 powerOffTime: 2.0.
 cameraCaptureDelay: 1.0.

Program Is Running...
Type Ctrl+c to stop the program.
start power off: 20171022072547
over power off and start power on: 20171022072549
capture a image: 20171022072550
over power on: 20171022072553
Capture image count: 1
start power off: 20171022072553
over power off and start power on: 20171022072555
capture a image: 20171022072556
over power on: 20171022072559
Capture image count: 2
start power off: 20171022072559
over power off and start power on: 20171022072602
capture a image: 20171022072603
over power on: 20171022072606
Capture image count: 3

三、图像相似度处理

目前没有整合图片相似度对比,不过test/imgcompare.py中有Ubuntu版本的处理图片相似度源代码,可以用于参考整合功能。下图中,中间一行图最后一张,目前不知道为什么显示的时候偏蓝:

  • 第一行图是表示test/tpl.jpg的直方图和图片;
  • 第二行图是表示test/src.jpg的直方图和图片;
  • 第三行图是表示,BGR对应的三个相似度和最后一个取BGR最小的相似度。

img/Ubuntu_JPG_Compare.png

如下是GIMP图像处理软件对test/src.jpgtest/tpl.jpg显示的BGR直方图:

3.1 test/tpl.jpg直方图

和前面的Python输出的BGR直方图拟合度是一样的。

img/tpl_blue.pngimg/tpl_green.pngimg/tpl_red.png

3.2 test/src.jpg直方图

和前面的Python输出的BGR直方图拟合度是一样的。

img/src_blue.pngimg/src_green.pngimg/src_red.png

3.3 颜色偏蓝原因

OpenCV represents RGB images as multi-dimensional NumPy arrays…, but in reverse order! This means that images are actually represented in BGR order rather than RGB! There’s an easy fix though. All we need to do is convert the image from BGR to RGB:

plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))

3.4 显示颜色正常

img/Color_OK.png

About

Raspberry Pi 2B使用USB Camera获取图片,OpenCV分析图片相识度,决定Relay是否触发开关。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages