visionlabs / torch-opencv Goto Github PK
View Code? Open in Web Editor NEWOpenCV bindings for Torch.
License: MIT License
OpenCV bindings for Torch.
License: MIT License
It's currently very complicated to tie FrameSource
to SuperResolution
in Lua. Probably we should change PtrWrapper
to point to Ptr<SomeAlgorithm>
rather than to SomeAlgorithm
.
Creating this as a reminder to myself
See demo/cuda/resize.lua (now works only with grayscale images)
Priority testing:
Class-based stuff including algorithms:
Separate functions (filters, detectors, ...):
Class-based stuff including algorithms:
Separate functions (filters, detectors, ...):
Classes:
I couldn't find corresponding OpenCV include files (candidates are superres/optical_flow.hpp
, videostab/optical_flow.hpp
and video/tracking.hpp
). Current docs on optflow don't match with these!
Scanning dependencies of target optflow
[ 65%] Building CXX object CMakeFiles/optflow.dir/src/optflow.cpp.o
In file included from /Users/eugenioculurciello/Code/Lua/torch-opencv/src/optflow.cpp:1:
In file included from /Users/eugenioculurciello/Code/Lua/torch-opencv/include/optflow.hpp:3:
/Users/eugenioculurciello/Code/Lua/torch-opencv/include/video.hpp:4:10: fatal error: 'opencv2/bgsegm.hpp' file not found
^
1 error generated.
make[2]: *** [CMakeFiles/optflow.dir/src/optflow.cpp.o] Error 1
make[1]: *** [CMakeFiles/optflow.dir/all] Error 2
make: *** [all] Error 2
...results in a segfault when calling superRes->nextFrame()
. Otherwise it sets Farneback optical flow by default and works fine.
I'm stuck deep in debug with that, couldn't figure out the root of the problem. To be fixed later, possibly by someone else.
I tried to build torch-opencv on Ubuntu 14.04.3 LTS:
In file included from /home/koepf/torch/install/include/TH/THVector.h:24:0,
from /home/koepf/torch/install/include/TH/TH.h:12,
from /home/koepf/code/torch-opencv/include/Common.hpp:5,
from /home/koepf/code/torch-opencv/src/Common.cpp:1:
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/smmintrin.h:31:3: error: #error "SSE4.1 instruction set not enabled"
# error "SSE4.1 instruction set not enabled"
Any ideas?
Tonemap
TonemapDrago
TonemapDurand
TonemapReinhard
TonemapMantiuk
AlignExposures
AlignMTB
CalibrateCRF
CalibrateDebevec
CalibrateRobertson
MergeExposures
MergeDebevec
MergeMertens
MergeRobertson
Hi, if I have an image already in a tensor, how can I convert it to opencv format?
To-do: copy to-do list from #19
BackgroundSubtractor
BackgroundSubtractorMOG2
BackgroundSubtractorKNN
working on it myself
Hello,
I tried to execute the demo/videocap.lua using opencv 3.0 as specified and it's not working properly.
I found the problem to be in line 20:
edges = cv.cvtColor{frame, cv.COLOR_BGR2GRAY}
the problem is that "edges" needs to passed as an argument also:
edges = cv.cvtColor{frame, edges, cv.COLOR_BGR2GRAY}
and now everything works fine.
Just posted the issue, in case anyone else encounters the same problem.
Thank you!
I am encountering the following error probably because some functions were moved into opencv_contrib. I am currently using the command:
OpenCV_DIR="/home/karan/opencv" luarocks install cv
How do I include contrib folder?
Error that I got:
/tmp/luarocks_cv-scm-1-490/torch-opencv/src/optflow.cpp: In function โTensorWrapper calcOpticalFlowSparseToDense(TensorWrapper, TensorWrapper, TensorWrapper, int, int, float, bool, float, float)โ:
/tmp/luarocks_cv-scm-1-490/torch-opencv/src/optflow.cpp:54:9: error: โcalcOpticalFlowSparseToDenseโ is not a member of โoptflowโ
optflow::calcOpticalFlowSparseToDense(
^
/tmp/luarocks_cv-scm-1-490/torch-opencv/src/optflow.cpp:54:9: note: suggested alternative:
/tmp/luarocks_cv-scm-1-490/torch-opencv/src/optflow.cpp:48:22: note: โcalcOpticalFlowSparseToDenseโ
struct TensorWrapper calcOpticalFlowSparseToDense(
^
/tmp/luarocks_cv-scm-1-490/torch-opencv/src/optflow.cpp:59:9: error: โcalcOpticalFlowSparseToDenseโ is not a member of โoptflowโ
optflow::calcOpticalFlowSparseToDense(
^
/tmp/luarocks_cv-scm-1-490/torch-opencv/src/optflow.cpp:59:9: note: suggested alternative:
/tmp/luarocks_cv-scm-1-490/torch-opencv/src/optflow.cpp:48:22: note: โcalcOpticalFlowSparseToDenseโ
struct TensorWrapper calcOpticalFlowSparseToDense(
^
/tmp/luarocks_cv-scm-1-490/torch-opencv/src/optflow.cpp: In function โDenseOpticalFlowPtr createOptFlow_SparseToDense_optflow()โ:
/tmp/luarocks_cv-scm-1-490/torch-opencv/src/optflow.cpp:151:32: error: โcreateOptFlow_SparseToDenseโ is not a member of โoptflowโ
return rescueObjectFromPtr(optflow::createOptFlow_SparseToDense());
^
CMakeFiles/optflow.dir/build.make:54: recipe for target 'CMakeFiles/optflow.dir/src/optflow.cpp.o' failed
make[2]: *** [CMakeFiles/optflow.dir/src/optflow.cpp.o] Error 1
CMakeFiles/Makefile2:340: recipe for target 'CMakeFiles/optflow.dir/all' failed
make[1]: *** [CMakeFiles/optflow.dir/all] Error 2
Makefile:116: recipe for target 'all' failed
make: *** [all] Error 2
Error: Build error: Failed building.
I am having problems trying to use BFMatcher. I am doing the following (similar to the flann demo)
matcher = cv.BFMatcher{cv.NORM_L2, False}
print (matcher)
local N_samples, N_features, fieldSize, N_query = 300, 2, 600, 20
local samples = torch.rand(N_samples, N_features):float() * fieldSize
local query = torch.rand(1, N_features):float() * fieldSize
local res = matcher:match{query, samples}
and I am getting
features2d/init.lua:1391: bad argument #1 to 'DescriptorMatcher_match_trainDescriptors' (cannot convert 'struct TensorWrapper' to 'struct PtrWrapper')
I readed init.lua but I don't see what I am doing wrong.
I cannot compile on Os X with brew:
$ brew install opencv
Warning: homebrew/science/opencv-2.4.12 already installed
$ make
Scanning dependencies of target Common
[ 3%] Building CXX object CMakeFiles/Common.dir/src/Common.cpp.o
In file included from /Users/eugenioculurciello/Code/Lua/torch-opencv/src/Common.cpp:1:
/Users/eugenioculurciello/Code/Lua/torch-opencv/include/Common.hpp:2:10: fatal error: 'opencv2/core.hpp' file not found
^
1 error generated.
make[2]: *** [CMakeFiles/Common.dir/src/Common.cpp.o] Error 1
make[1]: *** [CMakeFiles/Common.dir/all] Error 2
make: *** [all] Error 2
I fix that:
on os x, it is: opencv2/cora/core.hpp
then:
$ make
Scanning dependencies of target Common
[ 3%] Building CXX object CMakeFiles/Common.dir/src/Common.cpp.o
In file included from /Users/eugenioculurciello/Code/Lua/torch-opencv/src/Common.cpp:1:
/Users/eugenioculurciello/Code/Lua/torch-opencv/include/Common.hpp:146:30: error: no type named 'Moments' in namespace 'cv'
MomentsWrapper(const cv::Moments & other);
~~~~^
/Users/eugenioculurciello/Code/Lua/torch-opencv/include/Common.hpp:147:25: error: no type named 'Moments' in namespace 'cv'
inline operator cv::Moments() {
~~~~^
/Users/eugenioculurciello/Code/Lua/torch-opencv/src/Common.cpp:154:42: error: no type named 'Moments' in namespace 'cv'
MomentsWrapper::MomentsWrapper(const cv::Moments & other) {
~~~~^
3 errors generated.
make[2]: *** [CMakeFiles/Common.dir/src/Common.cpp.o] Error 1
make[1]: *** [CMakeFiles/Common.dir/all] Error 2
make: *** [all] Error 2
THis I am not sure, is this platform dependent?
Hi.
torch-opencv looks like a good project, but I am having problems using it. I am on Ubuntu Linux 14.04 on x86_64 hardware. I have torch7 and opencv-3.0.0 installed and have been using both for some time. Up to now I have used the C++ interface to opencv, but I would like to interface to it from torch. So I downloaded torch-opencv-master.zip, and built torch-opencv with the commands:
unzip torch-opencv-master.zip
cd torch-opencv-master
mkdir build && cd build
cmake .. -DOpenCV_DIR=/usr/local/opencv-3.0.0/share/OpenCV
make
The configuration phase seemed to go ok, except for the warning about opencv_optflow:
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Warning at /usr/local/opencv-3.0.0/share/OpenCV/OpenCVConfig.cmake:219 (message):
opencv_optflow is required but was not found
Call Stack (most recent call first):
CMakeLists.txt:17 (FIND_PACKAGE)
-- Found Torch7 in /home/david/torch/install
-- Configuring done
-- Generating done
-- Build files have been written to: /home/david/torch/torch-opencv-master/build
The build appeared to succeed, but now I can't figure out how to tell luajit where to find torch-opencv, in other words how to get "require 'cv'" to work. I imagine that once you create a rockspec I will be able to just run "luarocks install", but meanwhile I'm not sure what symlinks I need to make and/or paths to set to connect torch's luajit to torch-opencv.
I appreciate any help you can provide.
Thanks,
-- Dave Slate
Classes:
OMG, I shouldn't have mentioned all these functions here
TrainData
StatModel
NormalBayesClassifier
KNearest
SVM
Kernel
EM
DTrees
RTrees
Boost
ANN_MLP
LogisticRegression
(Probably) try to load modules only on demand after local cv = require 'cv'
like it's done here:
https://github.com/stevedonovan/Penlight/blob/master/lua/pl/import_into.lua
Even if we decide not to use this, I still have troubles with splitting package into submodules. How to make this work without a global table?
local cv = require 'cv'
require 'cv.imgproc'
After a successful build in Ubuntu 64 14.04.2, some libraries can be loaded e.g. highgui, but some cannot e.g. imgproc and videoio:
local cv = require 'cv'
require 'cv.imgproc' -- image processing
produces:
/home/omid/torch/install/share/lua/5.1/trepl/init.lua:363: /home/omid/torch/install/share/lua/5.1/trepl/init.lua:363: /home/omid/torch/install/share/lua/5.1/torch/init.lua:65: bad argument #2 to 'newmetatable' (parent class name or nil expected)
stack traceback:
[C]: in function 'error'
/home/omid/torch/install/share/lua/5.1/trepl/init.lua:363: in function 'require'
[string "require 'cv.imgproc' -- image processing"]:1: in main chunk
[C]: in function 'xpcall'
/home/omid/torch/install/share/lua/5.1/trepl/init.lua:648: in function 'repl'
...omid/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk
[C]: at 0x00406670
demo/denoising.lua
shrubb@samsung:~/Projects/opencv.torch$ th demo/denoising.lua ~/Pictures/2015-09-09/DSC_2191_o.jpg ~/Pictures/2015-09-09/DSC_2191_o.jpg
*** Error in `/home/shrubb/Programs/Torch/install/bin/luajit': malloc(): memory corruption: 0x0000000001d1f4d0 ***
Aborted (core dumped)
Classes:
What we do need at the time being is a good code coverage by unit tests. How should we organize these tests? What will be the script to run? etc.
Hi,
I've tried to run this functionality with web cam and it runs well. But I could not run it with any video file.
I tried this:
th> cap = cv.VideoCapture{filename='/home/user/MH.avi'}
th> cap:isOpened()
false
Hi.
I have one more question related to my closed issue "Problems using torch-opencv #46". It looks like I can now run cv from the torch-opencv-master directory. However, I still have not figured out how to successfully access cv from other directories. No matter how I try to set paths, torch still has trouble finding the right ".lua" and/or ".so" files. Can you tell me exactly what I need to do so torch-opencv works when th is launched in a different directory?
Thanks.
Currently, we use this style:
function cv.GaussianBlur(t)
local src = assert(t.src)
local dst = t.dst
local ksize = cv.Size(assert(t.ksize))
-- ....
You may notice that it's not very pleasant to call all the functions this way, as you'll have to either memorize all the argument names or to consult OpenCV docs right along:
cv.GaussianBlur{
src = image,
dst = image,
ksize = {7,7},
sigmaX = 1.5,
sigmaY = 1.5
}
cv.Canny{
image = image,
edges = edges,
threshold1 = 0,
threshold2 = 30,
apertureSize = 3
}
cv.demosaicing{_src=edges _dst=edges, code=2}
cv.imshow{winname="an image", image=edges}
cv.waitKey{delay=30}
That's why it may be a good idea to support positional arguments as well:
function cv.GaussianBlur(t)
local src = assert(t[1] or t.src)
local dst = t[2] or t.dst
local ksize = cv.Size(assert(t[3] or t.ksize))
local sigmaX = assert(t[4] or t.sigmaX)
local sigmaY = t[5] or t.sigmaY or 0
local borderType = t[6] or t.borderType or cv.BORDER_DEFAULT
-- ...
end
I suggest that we should use this style from now on. I'll write a script to modify all the previous code.
I know this great project is in its alpha/beta stage, but I decided to try it nevertheless:). Maybe I just expect too much from Tensor-Mat conversion, but it seems to me that it assumes contiguous Tensors and different dimension ordering than it is common in Torch (WHC instead of CHW).
Specifically, I want to call cv.resize(). I tried lots of variants (leading to segfaults, weird results or failed asserts in _OutputArray::create()) but this is the only thing which works for me:
local img = torch.FloatTensor(4, 128, 128)
img = cv.resize{src=img:transpose(1, 3):contiguous(), dsize={256, 256}}
img = img:transpose(1, 3):contiguous()
Can the transposition be maybe hidden inside TensorWrapper? Can't really OpenCV work with non-contiguous tensors? I'm I doing something really wrong?
I know that it was not in the original proposal, but I realized that we could do some cool demos with it. Is it difficult to wrap?
TrainData
StatModel
NormalBayesClassifier
KNearest
SVM
EM
DTrees
RTrees
Boost
ANN_MLP
LogisticRegression
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.