php - PHP - Black image detection and Ignore text. How?
问题描述
My security cam has a failure, sometimes at the movement, the first snaps are black. That’s not a really a problem but I was looking for a way to delete those black images via a PHP script.
This one works great with a fully black images:
<?php
function check_if_black($src){
$img = imagecreatefromjpeg($src);
list($width_orig, $height_orig)=getimagesize($src);
for($i=0;$i<20;$i++){
$rand_width=rand ( 0 , $width_orig );
$rand_height=rand ( 0 , $height_orig );
$rgb = imagecolorat($img, $rand_width, $rand_height);
if($rgb!=0){
return "not black";
}
}
return "black";
}
?>
My snaps have a white timestamp on it. Always in the same position and always with white text. With the code I posted above it says the image isn't black. But 80%
of it is. Is there a way to detect if the snapshot is black and ignores the white timestamp on it?
解决方案
如果时间戳将放置在图像的底部意味着,您可以忽略底部的一些高度,然后获取图像的宽度和高度。现在你将只有黑色图像
function check_if_black($src){
$img = imagecreatefromjpeg($src);
list($width_orig, $height_orig)=getimagesize($src);
$height_orig=$height_orig-20;//Reduce some height(Ex 20px) here
for($i=0;$i<20;$i++){
$rand_width=rand ( 0 , $width_orig );
$rand_height=rand ( 0 , $height_orig );
$rgb = imagecolorat($img, $rand_width, $rand_height);
if($rgb!=0){
return "not black";
}
}
return "black";
}
推荐阅读
- wordpress - 显示正方形的元素图标
- javascript - 使用“使用信用卡或借记卡付款”付款时,PayPal 收据电子邮件不显示产品描述
- python - 如何使用 python 在graphviz中使用新的节点形状?
- r - 基于 R 中的条件对嵌套列表进行子集化
- powershell-2.0 - 需要重新启动远程服务器并使用 powershell 脚本发送电子邮件
- android - 无法在我的手机上安装我的第一个 android 应用程序,可安装在其他手机上
- sql - 带有 blazor 服务器端的 Include() EntityFramework Core 的问题
- python - Python - 是否会跳过“on_message”处理期间收到的 Websocket 消息?
- android - Android Studio 北极狐 | 2020.3.1 Canary 15 |撰写构建错误:找不到 androidx.compose:compose-compiler:1.0.0-beta06 |
- jms - 在 ActiveMQ 上调用 gRPC?