i2c_core.c






501 struct i2c_client *
502 i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)

i2c_new_device(...)依据注册的struct i2c_adapter 和 struct  i2c_board_info 来初始化 struct  i2c_client 并返回 struct i2c_client ,并且 struct i2c_client 的 client->dev.bus 被初始化为 &i2c_bus_type 。struct   i2c_bus_type 成员 i2c_device_probe 用来匹配i2c_driver 和 i2c_client 中的 name 域。

315 struct bus_type i2c_bus_type = {
316         .name           = "i2c",
317         .match          = i2c_device_match,
318         .probe          = i2c_device_probe,
319         .remove         = i2c_device_remove,
320         .shutdown       = i2c_device_shutdown,
321         .pm             = &i2c_device_pm_ops,
322 };
323 EXPORT_SYMBOL_GPL(i2c_bus_type);




相关函数实现源码如下:

485 /**
486  * i2c_new_device - instantiate an i2c device
487  * @adap: the adapter managing the device
488  * @info: describes one I2C device; bus_num is ignored
489  * Context: can sleep
490  *
491  * Create an i2c device. Binding is handled through driver model
492  * probe()/remove() methods.  A driver may be bound to this device when we
493  * return from this function, or any later moment (e.g. maybe hotplugging will
494  * load the driver module).  This call is not appropriate for use by mainboard
495  * initialization logic, which usually runs during an arch_initcall() long
496  * before any i2c_adapter could exist.
497  *
498  * This returns the new i2c client, which may be saved for later use with
499  * i2c_unregister_device(); or NULL to indicate an error.
500  */
501 struct i2c_client *
502 i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
503 {
504         struct i2c_client       *client;
505         int                     status;
506 
507         client = kzalloc(sizeof *client, GFP_KERNEL);
508         if (!client)
509                 return NULL;
510 
511         client->adapter = adap;
512 
513         client->dev.platform_data = info->platform_data;
514 
515         if (info->archdata)
516                 client->dev.archdata = *info->archdata;
517 
518         client->flags = info->flags;
519         client->addr = info->addr;
520         client->irq = info->irq;
521 
522         strlcpy(client->name, info->type, sizeof(client->name));
523 
524         /* Check for address validity */
525         status = i2c_check_client_addr_validity(client);
526         if (status) {
527                 dev_err(&adap->dev, "Invalid %d-bit I2C address 0x%02hx\n",
528                         client->flags & I2C_CLIENT_TEN ? 10 : 7, client->addr);
529                 goto out_err_silent;
530         }
531 
532         /* Check for address business */
533         status = i2c_check_addr_busy(adap, client->addr);
534         if (status)
535                 goto out_err;
536 
537         client->dev.parent = &client->adapter->dev;
538         client->dev.bus = &i2c_bus_type;
539         client->dev.type = &i2c_client_type;
540         client->dev.of_node = info->of_node;
541 
542         dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
543                      client->addr);
544         status = device_register(&client->dev);
545         if (status)
546                 goto out_err;
547 
548         dev_dbg(&adap->dev, "client [%s] registered with bus id %s\n",
549                 client->name, dev_name(&client->dev));
550 
551         return client;
552 
553 out_err:
554         dev_err(&adap->dev, "Failed to register i2c client %s at 0x%02x "
555                 "(%d)\n", client->name, client->addr, status);
556 out_err_silent:
557         kfree(client);
558         return NULL;
559 }
560 EXPORT_SYMBOL_GPL(i2c_new_device);











改变通道数,代码如何修改public static String[] multiPlateRecognise(opencv_core.Mat mat) { PlateDetect plateDetect = new PlateDetect(); plateDetect.setPDLifemode(true); Vector<opencv_core.Mat> matVector = new Vector<opencv_core.Mat>(10); if (0 == plateDetect.plateDetect(mat, matVector)) { if (matVector.size() > 0) { //字符分割与识别 return new String[]{cr.charsRecognise(matVector.get(0))}; } } return null;public static void main(String[] args) { // 多张车牌图片路径 String[] imgPaths = {"res/image/test_image/plate_locate.jpg", "res/image/test_image/test.jpg", "res/image/test_image/plate_detect.jpg", "res/general_test/京A88731.jpg"}; int sum = imgPaths.length; // 总共处理的图片数量 int errNum = 0; // 识别错误的数量 int sumTime = 0; // 总耗时 long longTime = 0; // 最长处理时长 for (int i = 0; i < sum; i++) { opencv_core.Mat src = opencv_imgcodecs.imread(imgPaths[i]); String[] ret = multiPlateRecognise(src); long now = System.currentTimeMillis(); System.err.println(Arrays.toString(ret)); long s = System.currentTimeMillis() - now; if (s > longTime) { longTime = s; } sumTime += s; boolean flag =false;//是否有一个车牌号识别错误 for (String plate:ret) { if (plate == null) { continue; } String targetPlate = getTargetPlate(imgPaths[i]); if (!plate.equals(targetPlate)){ flag = true; break; } } if (flag) { errNum++; } } BigDecimal errSum = new BigDecimal(errNum); BigDecimal sumNum = new BigDecimal(sum); BigDecimal c = sumNum.subtract(errSum).divide(sumNum,2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); System.err.println("总耗时:" + sumTime + "ms,平均处理时长:" + sumTime/sum + "ms,错误数量:" + errNum + ",正确识别率:" + c + "%"); } }
最新发布
06-11
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值