Board logo

标题: [其他] [已解决]能把拉花的照片从众多照片里面剔出来吗? [打印本页]

作者: a475012621    时间: 2023-7-11 13:55     标题: [已解决]能把拉花的照片从众多照片里面剔出来吗?

<a href="https://imgse.com/i/pCWQcjO"><img src="https://s1.ax1x.com/2023/07/11/pCWQcjO.md.jpg" alt="pCWQcjO.jpg" border="0" /></a>https://s1.ax1x.com/2023/07/11/pCWQcjO.jpg
作者: a475012621    时间: 2023-7-11 14:01

如题,能不能处理这种照片,或者说从众多的照片里面把这些拉花的照片找出来
作者: pd1    时间: 2023-7-11 20:47

本帖最后由 pd1 于 2023-7-11 20:49 编辑

需要多发几张有问题和没问题的图片做数据对比。
类似opencv这样的程序的来处理
作者: a475012621    时间: 2023-7-12 09:15

回复 3# pd1 <img src="https://pic.imgdb.cn/item/64adfe8b1ddac507cc7eabc4.jpg">
作者: a475012621    时间: 2023-7-12 09:15

回复 3# pd1 https://pic.imgdb.cn/item/64adfe8b1ddac507cc7eabc4.jpg
作者: a475012621    时间: 2023-7-12 09:16

回复 3# pd1 https://pic.imgdb.cn/item/64adfed11ddac507cc7f8f2f.jpg
作者: a475012621    时间: 2023-7-12 09:17

回复 3# pd1

作者: pd1    时间: 2023-7-12 16:57

每一张花掉的地方颜色都不一样,不知道怎么搞
作者: idwma    时间: 2023-7-12 19:58

回复 8# pd1


    虽然颜色不一样
但都是在下半部分有色块,颜色数量10左右吧
不知道能不能这样,只统计下半部分所有像素的颜色,按颜色占比来判断
作者: a475012621    时间: 2023-7-13 15:47

回复 8# pd1


    好吧
作者: idwma    时间: 2023-7-14 10:24

实践一下应该可以找出花的图
  1. #@&cls&powershell "type '%~f0'|out-string|iex"&pause&exit
  2. Add-Type -AssemblyName System.Drawing
  3. $cp = New-Object CodeDom.Compiler.CompilerParameters
  4. $cp.ReferencedAssemblies.Add([Reflection.Assembly]::GetAssembly([Drawing.Image]).Location) >$null
  5. $cp.ReferencedAssemblies.Add([Reflection.Assembly]::GetAssembly([Linq.Enumerable]).Location) >$null
  6. $cp.CompilerOptions ='/unsafe'
  7. Add-Type -CompilerParameters $cp -TypeDefinition @'
  8. using System;
  9. using System.Drawing;
  10. using System.Drawing.Imaging;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. public class test
  14. {
  15.     unsafe public static int main(string f)
  16.     {
  17. Bitmap bitmap = new Bitmap(@f);
  18. int width = bitmap.Width;
  19. int height = bitmap.Height;
  20. int h = height/2;
  21. BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, h, width, height-h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
  22. byte* p = (byte*)(IntPtr)bitmapData.Scan0;
  23. Dictionary<int, int> b = new Dictionary<int, int>();
  24. for (int i = 0; i < width * (height-h) * 4; i+=4)
  25. {
  26.     int c = (p[i+3] << 24) | (p[i+2] << 16) | (p[i+1] << 8) | p[i];
  27.             b[c] = b.ContainsKey(c) ? b[c] + 1 : 1;
  28. }
  29. bitmap.UnlockBits(bitmapData);
  30. var d = b.OrderBy(x => x.Value).Select(x => x.Value).ToArray();
  31. return width*h/(d[d.Length-1]) < 30 ? 1 : 0;
  32.     }
  33. }
  34. '@
  35. dir *.jpg|%{if([test]::main($_.FullName)){$_.fullname}}
复制代码

作者: a475012621    时间: 2023-7-14 13:15

回复 11# idwma

测试能找出拉花的照片了,感谢
作者: wanghan519    时间: 2023-7-14 15:03

发现纠错的图像都含有很多这样的数据:a28a2800
所以想着直接找出含有这些数据的文件,在busybox for windows里可用
  1. find . -iname "*.jpg" -exec sh -c 'xxd -p "{}" | grep -q "a28a2800"' \; -print
复制代码

作者: a475012621    时间: 2023-7-14 15:33

回复 13# wanghan519


    感谢
作者: Batcher    时间: 2023-7-14 15:48

回复 13# wanghan519


    你试试用系统自带的画图程序做一个矩形,填充为纯色,例如红色,另存为jpg文件,看看是否也包含这个十六进制串?
作者: wanghan519    时间: 2023-7-14 17:17

回复 15# Batcher


   确实,纯白含有很多a28a2800,纯红则是a28a0028这种换了个位置的,很长一大坨连续的这种数据。
上面完全是猜的很不准
网上搜来的用imagemagick等判断图片是否损坏的方法都不会报错,可能这些图片都纠错过,还是用其他方法吧。。。
作者: 天津凯杰    时间: 2023-7-19 09:10

回复 11# idwma

这个测试过的确有用。能否改进下把挑选结果移动到一个文件夹下,或 统计输出名字到一个文档出来更完美。
作者: a475012621    时间: 2023-7-19 14:52

回复 11# idwma

#@&cls&powershell "type '%~f0'|out-string|iex"&pause&exit
Add-Type -AssemblyName System.Drawing
$cp = New-Object CodeDom.Compiler.CompilerParameters
$cp.ReferencedAssemblies.Add([Reflection.Assembly]::GetAssembly([Drawing.Image]).Location) >$null
$cp.ReferencedAssemblies.Add([Reflection.Assembly]::GetAssembly([Linq.Enumerable]).Location) >$null
$cp.CompilerOptions ='/unsafe'

Add-Type -CompilerParameters $cp -TypeDefinition @'
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections.Generic;
using System.Linq;

public class test
{
    unsafe public static int main(string f)
    {
        Bitmap bitmap = new Bitmap(@f);
        int width = bitmap.Width;
        int height = bitmap.Height;
        int h = height/2;
        BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, h, width, height-h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
        byte* p = (byte*)(IntPtr)bitmapData.Scan0;
        Dictionary<int, int> b = new Dictionary<int, int>();
        for (int i = 0; i < width * (height-h) * 4; i+=4)
        {
            int c = (p[i+3] << 24) | (p[i+2] << 16) | (p[i+1] << 8) | p;
            b[c] = b.ContainsKey(c) ? b[c] + 1 : 1;
        }
        bitmap.UnlockBits(bitmapData);
        var d = b.OrderBy(x => x.Value).Select(x => x.Value).ToArray();
        return width*h/(d[d.Length-1]) < 30 ? 1 : 0;
    }
}
'@

mkdir 123
dir *.jpg|%{if([test]::main($_.FullName)){move $_.fullname '123'}}
作者: a475012621    时间: 2023-7-19 14:54

回复 11# idwma
我加了你说的创建文件夹那句话过后运行他提示我+ ~~~~~~~~~
    + CategoryInfo          : ResourceExists: (C:\Users\Admin\Desktop\新建文件夹\123:String) [New-Item], IOException
    + FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.NewItemCommand

move : 另一个进程正在使用此文件,因此该进程无法访问此文件。
所在位置 行:39 字符: 43
+ dir *.jpg|%{if([test]::main($_.FullName)){move $_.fullname '123'}}
+                                           ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\Users\Admin\Desktop\新建文件夹\003.jpg:FileInfo) [Move-Item], IOException
    + FullyQualifiedErrorId : MoveFileInfoItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand

move : 另一个进程正在使用此文件,因此该进程无法访问此文件。
所在位置 行:39 字符: 43
+ dir *.jpg|%{if([test]::main($_.FullName)){move $_.fullname '123'}}
+                                           ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\Users\Admin\Desktop\新建文件夹\005.jpg:FileInfo) [Move-Item], IOException
    + FullyQualifiedErrorId : MoveFileInfoItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand
作者: idwma    时间: 2023-7-19 16:29

  1. #@&cls&powershell "type '%~f0'|out-string|iex"&pause&exit
  2. Add-Type -AssemblyName System.Drawing
  3. $cp = New-Object CodeDom.Compiler.CompilerParameters
  4. $cp.ReferencedAssemblies.Add([Reflection.Assembly]::GetAssembly([Drawing.Image]).Location) >$null
  5. $cp.ReferencedAssemblies.Add([Reflection.Assembly]::GetAssembly([Linq.Enumerable]).Location) >$null
  6. $cp.CompilerOptions ='/unsafe'
  7. Add-Type -CompilerParameters $cp -TypeDefinition @'
  8. using System;
  9. using System.Drawing;
  10. using System.Drawing.Imaging;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. public class test
  14. {
  15.     unsafe public static int main(string f)
  16.     {
  17. Bitmap bitmap = new Bitmap(@f);
  18. int width = bitmap.Width;
  19. int height = bitmap.Height;
  20. int h = height/2;
  21. BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, h, width, height-h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
  22. byte* p = (byte*)(IntPtr)bitmapData.Scan0;
  23. Dictionary<int, int> b = new Dictionary<int, int>();
  24. for (int i = 0; i < width * (height-h) * 4; i+=4)
  25. {
  26.     int c = (p[i+3] << 24) | (p[i+2] << 16) | (p[i+1] << 8) | p[i];
  27.             b[c] = b.ContainsKey(c) ? b[c] + 1 : 1;
  28. }
  29. bitmap.UnlockBits(bitmapData);
  30.         bitmap.Dispose();
  31. var d = b.OrderBy(x => x.Value).Select(x => x.Value).ToArray();
  32. return width*h/(d[d.Length-1]) < 30 ? 1 : 0;
  33.     }
  34. }
  35. '@
  36. mkdir 123
  37. $a=dir *.jpg|%{if([test]::main($_.FullName)){move $_.fullname '123'}}
复制代码

作者: 天津凯杰    时间: 2023-7-19 19:15

OK 完美测试通过,非常好的脚本,建议收藏
作者: a475012621    时间: 2023-7-20 12:18

回复 20# idwma


感谢感谢,达到效果了




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2