zoukankan      html  css  js  c++  java
  • 京东商城图片价格识别

        因项目需要,花了点时间做了个小程序来演示京东商城的图片价格识别,初步试用效果还不错。

        先上个图:

    用了个最简单的算法:

    /// <summary>
            
    /// 图片解码
            
    /// </summary>
            
    /// <param name="srcBitmap">0-9和.的源图像</param>
            
    /// <param name="distBitmap">目标图像</param>
            
    /// <returns></returns>
            public static string DecodeGrayBitmap(IList<Bitmap> srcBitmap, Bitmap[] distBitmap)
            {
                StringBuilder sb 
    = new StringBuilder();

                
    foreach (Bitmap dist in distBitmap)
                {
                    
    int val = 0;
                    
    double max = 0;

                    
    for (int pos = 0; pos < srcBitmap.Count; pos++)
                    {
                        
    double n = ClacMatchRate(srcBitmap[pos], dist);

                        
    if (n > max)
                        {
                            max 
    = n;
                            val 
    = pos;
                        }

                        
    if (max > 0.9)
                            
    break;
                    }

                    
    if (val == 10)
                    {
                        sb.Append(
    '.');
                    }
                    
    else
                    {
                        sb.Append(val);
                    }
                }

                
    return sb.ToString();
            }

            
    public static double ClacMatchRate(Bitmap src, Bitmap dist)
            {
                
    double black = 0;
                
    double match = 0;

                
    int w = src.Width < dist.Width ? src.Width : dist.Width, h = src.Height < dist.Height ? src.Height : dist.Height;

                
    for (int x = 0; x < w; x++)
                {
                    
    for (int y = 0; y < h; y++)
                    {
                        
    int sc = PixelGrayValue(src.GetPixel(x, y));
                        
    int dc = PixelGrayValue(dist.GetPixel(x, y));

                        
    if (sc == 0 || dc == 0)
                        {
                            black
    ++;

                            
    if (sc == dc)
                                match
    ++;
                        }
                    }
                }

                
    return match / black;
            }


  • 相关阅读:
    Mysql 5.6 源码编译安装
    Python中的数据类型之字符串
    Python中变量的命名与使用(个人总结)
    Windows环境下python3.7版本怎么安装pygame
    web应用无法访问的原因之一以及如何设置数据库编码
    项目代码设计规范总结之分页查询
    当java web项目部署到服务器上时,无法将图片等媒体文件保存到服务器的最终奥义
    如何查看服务器上打印的信息
    java代码实现JVM栈溢出,堆溢出
    springmvc源码分析(转)
  • 原文地址:https://www.cnblogs.com/afxcn/p/2067539.html
Copyright © 2011-2022 走看看