Sajjad Taheri
Donald Bren School of Computer Science, UCIrvine
asm.js
asm.js is typed subet of JavaScript offering near native performance
OpenCV C++ code
LLVM Bitcode
Emscripten is a source to source compiler from Mozilla
Binding glue code
LLVM Bitcode
Bind C++ entities to JavaScript so can be used as a normal
void erode(){
// Read image
Mat image,dst;
image = imread("image.jpg", CV_LOAD_IMAGE_COLOR);
// Create a structuring element
int erosion_size = 6;
Mat element = getStructuringElement(cv::MORPH_RECT,
cv::Size(2 * erosion_size + 1, 2 * erosion_size + 1),
cv::Point(erosion_size, erosion_size) );
// Apply erosion or dilation on the image
erode(image,dst,element);
}
function erode(){
// Read image
var src = cv.imread("image.jpg",
cv.CV_LOAD_IMAGE_COLOR.value);
var dst = new cv.Mat();
// Create a structuring element
var erosion_type = cv.cv_MorphShapes.MORPH_RECT.value;
var erosion_size=new cv.Size(2*Control.erosion_size+1,
2*Control.erosion_size+1 );
var element = cv.getStructuringElement( erosion_type
,erosion_size ) ;
// Apply erosion or dilation on the image
cv.erode(src, dst, element) ;
}
function __ZN2cv8haar_cvtL7convertERKNS_6StringES3_($oldcascade,
$newcascade){
}
CV_WRAP static bool convert(const String& oldcascade,
const String& newcascade){
}
CV_EXPORTS_W void erode( InputArray src,
OutputArray dst,
InputArray kernel,
Point anchor = Point(-1,-1),
int iterations = 1,
int borderType = BORDER_CONSTANT,
const Scalar& borderValue = morphologyDefaultBorderValue());
Most modules are covered
class CV_EXPORTS_W MSER : public Feature2D
{
public:
//! the full constructor
CV_WRAP static Ptr<MSER> create( int _delta=5, int _min_area=60, int _max_area=14400,
double _max_variation=0.25, double _min_diversity=.2,
int _max_evolution=200, double _area_threshold=1.01,
double _min_margin=0.003, int _edge_blur_size=5 );
CV_WRAP virtual void detectRegions( InputArray image,
CV_OUT std::vector<std::vector<Point> >& msers,
std::vector<Rect>& bboxes ) = 0;
CV_WRAP virtual void setDelta(int delta) = 0;
CV_WRAP virtual int getDelta() const = 0;
CV_WRAP virtual void setMinArea(int minArea) = 0;
CV_WRAP virtual int getMinArea() const = 0;
CV_WRAP virtual void setMaxArea(int maxArea) = 0;
CV_WRAP virtual int getMaxArea() const = 0;
CV_WRAP virtual void setPass2Only(bool f) = 0;
CV_WRAP virtual bool getPass2Only() const = 0;
};
Image/Video are coming from HTML Canvas
Canvas API gets images in RGBA format
OpenCV likes RGB better
Canvas only supports data with 8 bits per pixels
depth data are represented with 16 bits per pixels
work in progress to fix this
emscripten::class_<cv::MSER ,base<Feature2D>>("MSER")
.function("getPass2Only",
select_overload<bool(cv::MSER&)>(&Wrappers::MSER_getPass2Only_wrap),
pure_virtual())
.function("setMinArea",
select_overload<void(cv::MSER&,int)>(&Wrappers::MSER_setMinArea_wrap),
pure_virtual())
.function("getDelta",
select_overload<int(cv::MSER&)>(&Wrappers::MSER_getDelta_wrap),
pure_virtual())
.class_function("create",
select_overload<Ptr<MSER>(int,int,int,double,double,int,double,double,int)>(&Wrappers::create_MSER_wrapper))
.function("getMaxArea",
select_overload<int(cv::MSER&)>(&Wrappers::MSER_getMaxArea_wrap),
pure_virtual())
.function("setMaxArea", select_overload<void(cv::MSER&,int)>(&Wrappers::MSER_setMaxArea_wrap),
pure_virtual())
.function("setPass2Only", select_overload<void(cv::MSER&,bool)>(&Wrappers::MSER_setPass2Only_wrap),
pure_virtual())
.function("getMinArea", select_overload<int(cv::MSER&)>(&Wrappers::MSER_getMinArea_wrap),
pure_virtual())
.function("detectRegions",
select_overload<void(cv::MSER&,
const cv::Mat&,
std::vector<std::vector<Point>>&,
std::vector<Rect>&)>(&Wrappers::MSER_detectRegions_wrap),
pure_virtual())
.function("setDelta",
select_overload<void(cv::MSER&,int)>(&Wrappers::MSER_setDelta_wrap),
pure_virtual())
;
Sources of penalty
how well browsers supports asm.js
Data should be copied into/from ASM.js heap
before computation
after computation
saved on this by returning a pointer to the heap
Wrapper functions overhead
Image format conversion
RGBA -> RGB and vice versa
Text