1

I'm looking for the most optimal way of extracting single color on background and replace it with some picture on the fly in JavaCV. I wrote very simple method reading pixel by pixel and replacing it if the color is green for example. This is very slow and even if I divided it into few threads it works dramatically slow. This must be done on live so I have to find out some other method. Perhaps I will have to add some watermark as well after background replacing, so the application must be quite fast.

Does anybody can help me finding right way of doing it ? I spend all day long trying to find other way of doing it, but.. all examples I have found doesn't work or maybe I do not know how to adopt them to my needs.

This guy (http://www.youtube.com/watch?v=WOEuE3D88b0) wrote that he is reading pixel by pixel - no way, or maybe he had very fast multi-core workstation. On my MacBook Pro 2.5 i5 it just doesn't work :(

I have used your example and I think that I have mixed it totally. I can see mask of moving me ( white on black background) and if I use CvCopy I can see background appearing at the places where white dots are. Unfortunatelly his is not requested result, but I think I must be very close to it ;) I have to leave me and replace all static objects. Could you please examine my code ?

private static final IplImage back = cvLoadImage("/Users/user/app/eclipse/JavaCV/resources/1.png", CV_LOAD_IMAGE_COLOR);

private static BackgroundSubtractorMOG2 bgs = new BackgroundSubtractorMOG2(30,16,false);

public static IplImage replacePixels2(IplImage img){
IplImage frame = cvCloneImage(img); 
//bgs.getBackgroundImage(frame);
IplImage image = IplImage.create(frame.width(), frame.height(), IPL_DEPTH_8U,1);
bgs.apply(frame, image, -1);


IplROI roi = new IplROI();
roi.xOffset(0);
roi.yOffset(0);
roi.width(frame.width());
roi.height(frame.height());


IplImage backImageWithRoi = frame.roi(roi);


cvCopy(back, backImageWithRoi, image );

    return backImageWithRoi;
}

I also tried grabCut but this is extremely slow and can't be used in changing stream on live :(

Best Regards Jan

johnnyGor
  • 161
  • 1
  • 3
  • 16

1 Answers1

1

Since JavaCV is an interface to OpenCV, then you must be able to perform Grabcut segmentation.

As answered here too.

Community
  • 1
  • 1
BitParser
  • 3,748
  • 26
  • 42
  • Dear TGO I tried to use Ex5GrabCut example, but it seams to be slow as well :(I do not have correct result yet, but frames are changing very slow and I'm not working on Full HD stream :( – johnnyGor Aug 17 '13 at 20:34
  • @johnnyGor are you executing the algorithm as you _preview_ it? – BitParser Aug 17 '13 at 21:17
  • I found some example. The values are taken from it. This is not finished yet, but at this step I noticed very low speed of it. public static IplImage bgTest(IplImage img){ IplImage frame = cvCloneImage(img); CvRect rect = new CvRect(0, 0, 200, 200); IplImage result = IplImage.create(cvGetSize(frame), IPL_DEPTH_8U, 1); CvMat a = new CvMat(null); CvMat b = new CvMat(null); grabCut(frame, result, rect, a, b, 3, GC_INIT_WITH_RECT); cvCmpS(result, GC_PR_FGD, result, CV_CMP_EQ); return result; } – johnnyGor Aug 17 '13 at 21:37
  • there are c++ examples such as [this one](http://mateuszstankiewicz.eu/?p=189) but I don't know whether they'll help. perhaps with some code rework to use it in java – BitParser Aug 17 '13 at 21:50
  • Dear TGO, I have updated my original post, Can I ask you to check it ? please ;) – johnnyGor Aug 19 '13 at 18:07