zoukankan      html  css  js  c++  java
  • Lua 调用 Opencv 的方法

     

    Lua 调用 Opencv 的方法

      

      最近想用 Lua 调用 Opencv 进行相关像素级操作,如:bitwise_and 或者 bitwise_or,从而完成图像 IoU 的计算。

      那么,怎么用 Lua 调用 Opencv 呢?

      查了 Torch 的官方文档,发现只有这么几个可以调用的包:

      链接: https://github.com/torch/torch7/wiki/Cheatsheet

     

        

      然后,你点击一个进去,发现有这么一个方法,可以安装对应的 Opencv 包:

      

        然后,你就在终端里输入: luarocks install cv ,发现半天没反应 。。。

      过了一会,有反应了,见下图:  

        然后,就是等待了,这个”龟速“ 真的不能忍!!!

      其实,这里并没有那么直接,因为,你发现,如果你没有下载好 Opencv 官方的软件包,安装的时候,会提示你错误,从而停止掉!

      

      所以,还是需要安装这个网页上提示的过程进行:https://github.com/VisionLabs/torch-opencv/wiki/Installation 

      首先,是下载安装 Opencv 官方的 3.1 Linux 版本文件;

      然后,确保你的 Torch 是没有问题的;

      然后就开始执行刚刚那一句:luarocks install cv,这里,如果你可以直接指定 Opencv 文件的路径,就更好了,即:

      例如: OpenCV_DIR="/home/wangxiao/opencv-3.1.0" luarocks install cv 

      然后,你能做的,就还是等待,等待,再等待 。。。 


      Sorry,又报错了:

        CMake Error at CMakeLists.txt:30 (FIND_PACKAGE):
        Could not find a configuration file for package "OpenCV" that is compatible
        with requested version "3.1".

        The following configuration files were considered but not accepted: 

        /home/wangxiao/opencv-3.1.0/cmake/OpenCVConfig.cmake, version: unknown
        /usr/share/OpenCV/OpenCVConfig.cmake, version: 2.4.9.1

        -- Configuring incomplete, errors occurred!
        See also "/tmp/luarocks_cv-scm-1-1973/torch-opencv/build/CMakeFiles/CMakeOutput.log".
        make: *** No targets specified and no makefile found. Stop.

      具体的是:

      

      

      此时的我,我特想打人。。。真的。。。

     

         后来找到一个关于求解 IoU 的帖子,来自于 Faster RCNN :  

     1 function o = boxoverlap(a, b)
     2 % Compute the symmetric intersection over union overlap between a set of
     3 % bounding boxes in a and a single bounding box in b.
     4 %
     5 % a  a matrix where each row specifies a bounding box
     6 % b  a matrix where each row specifies a bounding box
     7 
     8 % AUTORIGHTS
     9 % -------------------------------------------------------
    10 % Copyright (C) 2011-2012 Ross Girshick
    11 % Copyright (C) 2008, 2009, 2010 Pedro Felzenszwalb, Ross Girshick
    12 % 
    13 % This file is part of the voc-releaseX code
    14 % (http://people.cs.uchicago.edu/~rbg/latent/)
    15 % and is available under the terms of an MIT-like license
    16 % provided in COPYING. Please retain this notice and
    17 % COPYING if you use this file (or a portion of it) in
    18 % your project.
    19 % -------------------------------------------------------
    20 
    21 o = cell(1, size(b, 1));
    22 for i = 1:size(b, 1)
    23     x1 = max(a(:,1), b(i,1));
    24     y1 = max(a(:,2), b(i,2));
    25     x2 = min(a(:,3), b(i,3));
    26     y2 = min(a(:,4), b(i,4));
    27 
    28     w = x2-x1+1;
    29     h = y2-y1+1;
    30     inter = w.*h;
    31     aarea = (a(:,3)-a(:,1)+1) .* (a(:,4)-a(:,2)+1);
    32     barea = (b(i,3)-b(i,1)+1) * (b(i,4)-b(i,2)+1);
    33     % intersection over union overlap
    34     o{i} = inter ./ (aarea+barea-inter);
    35     % set invalid entries to 0 overlap
    36     o{i}(w <= 0) = 0;
    37     o{i}(h <= 0) = 0;
    38 end
    39 
    40 o = cell2mat(o);

       晚上回去,我找了找 Faster RCNN Torch版本的代码:

     1 function Rect.union(a, b)
     2   local minx = math.min(a.minX, b.minX)
     3   local miny = math.min(a.minY, b.minY)
     4   local maxx = math.max(a.maxX, b.maxX)
     5   local maxy = math.max(a.maxY, b.maxY)
     6   return Rect.new(minx, miny, maxx, maxy)
     7 end
     8 
     9 function Rect.intersect(a, b)
    10   local minx = math.max(a.minX, b.minX)
    11   local miny = math.max(a.minY, b.minY)
    12   local maxx = math.min(a.maxX, b.maxX)
    13   local maxy = math.min(a.maxY, b.maxY)
    14   if maxx >= minx and maxy >= miny then
    15     return Rect.new(minx, miny, maxx, maxy)
    16   else
    17     return Rect.empty()
    18   end
    19 end
    20 
    21 function Rect.IoU(a, b)
    22   local i = Rect.intersect(a, b):area() 
    23   return i / (a:area() + b:area() - i)
    24 end

       是的,这就是关于求解 IoU 的代码了,至于,怎么调用 Opencv,我想说的是,等我安装好工具包先(此刻已泪崩 。。。)

     

      

  • 相关阅读:
    WebDriverAgent入门篇-安装和使用
    5分钟了解TypeScript
    “软到不行”的WWDC2018
    IntelliJ idea 撤回(已经commit未push的)操作
    【java并发核心一】Semaphore 的使用思路
    Spring Boot 如何干掉 if else?
    到底什么是重入锁,拜托,一次搞清楚!
    mysql 递归查找菜单节点的所有子节点
    sql语句递归查询(start with)
    js实现对上传图片的路径转成base64编码,并且对图片进行压缩,实现预览功能1
  • 原文地址:https://www.cnblogs.com/wangxiaocvpr/p/6132231.html
Copyright © 2011-2022 走看看