Ask Your Question

vijai's profile - activity

2017-08-11 03:48:35 -0600 commented question Background subtraction not working in IOS

Agreed, Till now I never thought the problem is with opencv , I was actually hoping that the way I might be using BS is in some way wrong. Please if anyone can point it to me would be very useful. I believe its something very tiny I am not able to see.

2017-08-11 01:49:21 -0600 asked a question Background subtraction not working in IOS

This is my code to do the Background Subtraction, The looks like nothing happens, it shows what the camera shows and I dont see any subtracted foreground. And I am using version 3.2.0

My Code:

#import "CVWrapper_bs.hpp"
#include "stdio.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#import "opencv2/videoio/cap_ios.h"
#import "opencv2/video/background_segm.hpp"

@interface CVWrapper_bs () <CvVideoCameraDelegate>
{

}
@end

@implementation CVWrapper_bs

UIImageView * imageView_i;
CvVideoCamera * videoCamera;
cv::Mat previousFrame;

cv::Ptr<cv::BackgroundSubtractor> bs;
cv::Mat fgmask1;

-(void)startCamera:(UIImageView *) cameraImageView
{
    //[GMMImageProcessingModule createMixtureModelWithType:GMMModelTypeKNN];
    bs = cv::createBackgroundSubtractorKNN();

    imageView_i = cameraImageView;
    videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView_i];
    videoCamera.delegate = self;
    videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
    videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
    videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
    videoCamera.defaultFPS = 20;
    videoCamera.rotateVideo = true;
    [videoCamera start];


}


- (void)processImage:(cv::Mat &)image
{

    bs->apply(image, fgmask1);
    dispatch_async(dispatch_get_main_queue(), ^{
        imageView_i.image = [self UIImageFromCVMat:fgmask1];
    });
}


-(UIImage *)UIImageFromCVMat:(cv::Mat)cvMat
{
    NSData *data = [NSData dataWithBytes:cvMat.data length:cvMat.elemSize()*cvMat.total()];
    CGColorSpaceRef colorSpace;

    if (cvMat.elemSize() == 1) {
        colorSpace = CGColorSpaceCreateDeviceGray();
    } else {
        colorSpace = CGColorSpaceCreateDeviceRGB();
    }

    CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);

    // Creating CGImage from cv::Mat
    CGImageRef imageRef = CGImageCreate(cvMat.cols,                                 //width
                                        cvMat.rows,                                 //height
                                        8,                                          //bits per component
                                        8 * cvMat.elemSize(),                       //bits per pixel
                                        cvMat.step[0],                            //bytesPerRow
                                        colorSpace,                                 //colorspace
                                        kCGImageAlphaNone|kCGBitmapByteOrderDefault,// bitmap info
                                        provider,                                   //CGDataProviderRef
                                        NULL,                                       //decode
                                        false,                                      //should interpolate
                                        kCGRenderingIntentDefault                   //intent
                                        );


    // Getting UIImage from CGImage
    UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);
    CGDataProviderRelease(provider);
    CGColorSpaceRelease(colorSpace);

    return finalImage;
}

@end
2016-01-22 00:03:17 -0600 received badge  Enthusiast
2016-01-14 07:47:13 -0600 commented question Need to detect objects in a Video stream

Thank you... I have been googling and I am right now learning for to train my Cascade. When I google I get only links related to Cascade. I am not getting anything regarding matching (template or descriptors). And yes my detection is for a specific one. Can you point to to what is this matching. Or a link to it will also be helpfull.

2016-01-14 07:27:21 -0600 asked a question Need to detect objects in a Video stream

Hi, I am literally new to the Open CV technology. I spent few days on the basics of the Open CV. But as I need to kick start my work, which is to detect only a particular object (like a human) in a video Stream.

So any help towards this is much appreciated. Pointers to any Code base of process/concepts I need are required.

regards, Vijai