Ask Your Question

Tamajit's profile - activity

2015-07-16 00:12:06 -0500 commented answer cv::seamlessClone is getting error (matrix.cpp:2236: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function create) in ios

@LBerger i have implemented

if(msk.type() == CV_8UC3){
    NSLog(@"3 chnl");
}
else if(msk.type() == CV_8UC4){
    NSLog(@"4 chnl");
}
else if(msk.type() == CV_8UC2){
    NSLog(@"2 chnl");
}
else if(msk.type() == CV_8UC1){
    NSLog(@"1 chnl");
}

this code below

UIImageToMat([UIImage imageNamed:@"vinci_mask.png"], msk);

and it showing "1 chnl"

2015-07-15 08:28:45 -0500 asked a question cv::seamlessClone is getting error (matrix.cpp:2236: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function create) in ios
 UIImageToMat([UIImage imageNamed:@"lisa_opencv_poisson.png"], src);
 UIImageToMat([UIImage imageNamed:@"mona_opencv_poisson.png"], tar);
 UIImageToMat([UIImage imageNamed:@"vinci_mask.png"], msk);

cv::Mat out1;
cv::seamlessClone(src, tar, msk, cv::Point(tar.cols/2,tar.rows/2), out1, cv::NORMAL_CLONE); // crash in this line
UIImageWriteToSavedPhotosAlbum(MatToUIImage(out1), nil, nil, nil);

NB: src and msk have same size

2015-07-15 08:28:01 -0500 asked a question cv::seamlessClone is getting error (matrix.cpp:2236: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function create) in ios
 UIImageToMat([UIImage imageNamed:@"lisa_opencv_poisson.png"], src);
 UIImageToMat([UIImage imageNamed:@"mona_opencv_poisson.png"], tar);
 UIImageToMat([UIImage imageNamed:@"vinci_mask.png"], msk);

cv::Mat out1;
cv::seamlessClone(src, tar, msk, cv::Point(tar.cols/2,tar.rows/2), out1, cv::NORMAL_CLONE); // crash in this line
UIImageWriteToSavedPhotosAlbum(MatToUIImage(out1), nil, nil, nil);

NB: src and msk have same size

2015-07-15 08:27:59 -0500 asked a question cv::seamlessClone is getting error (matrix.cpp:2236: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function create) in ios
 UIImageToMat([UIImage imageNamed:@"lisa_opencv_poisson.png"], src);
 UIImageToMat([UIImage imageNamed:@"mona_opencv_poisson.png"], tar);
 UIImageToMat([UIImage imageNamed:@"vinci_mask.png"], msk);

cv::Mat out1;
cv::seamlessClone(src, tar, msk, cv::Point(tar.cols/2,tar.rows/2), out1, cv::NORMAL_CLONE); // crash in this line
UIImageWriteToSavedPhotosAlbum(MatToUIImage(out1), nil, nil, nil);

NB: src and msk have same size

2015-07-04 00:19:14 -0500 received badge  Enthusiast
2015-06-22 00:05:24 -0500 commented answer how to detect moving object ios

can you switch to opencv 3.0? or you have to use opencv 2.4.9 only??

2015-06-20 04:19:54 -0500 commented answer how to detect moving object ios

@nitin follow Step 1 (Step 1: follow this to setup your opencv camera) where, VideoCamera.mm is for orientation and ViewController.mm is your viewController class.. in that class you will find _mainDisplay which linked with storyboard(UIImageView)..

2015-06-20 02:34:47 -0500 received badge  Editor (source)
2015-06-20 02:31:34 -0500 commented answer how to detect moving object ios

change fgimg = cv::Scalar::all(0); to image = cv::Scalar::all(0); this will remove undeclared identifier "fgimg"..

can you tell me what is your opencv framework version. I have written this code on opencv 3.0.0. if you are using lower version then change bg_model->apply(img, fgmask, update_bg_model ? -1 : 0); to bg_model->operator()(img, fgmask, update_bg_model ? -1 : 0);

2015-06-20 00:59:45 -0500 answered a question how to detect moving object ios

Step 1: follow this to setup your opencv camera

Step 2: add this code to processImage delegate

- (void)processImage:(cv::Mat&)image
{
      //process here
      cv::cvtColor(image, img, cv::COLOR_BGRA2RGB);
      int fixedWidth = 270;
     cv::resize(img, img, cv::Size(fixedWidth,(int)((fixedWidth*1.0f)*   (image.rows/(image.cols*1.0f)))),cv::INTER_NEAREST);

    //update the model
    bg_model->apply(img, fgmask, update_bg_model ? -1 : 0);

    GaussianBlur(fgmask, fgmask, cv::Size(7, 7), 2.5, 2.5);
    threshold(fgmask, fgmask, 10, 255, cv::THRESH_BINARY);

    image = cv::Scalar::all(0);
    img.copyTo(image, fgmask);
}

You'll need to declare following as global variable

cv::Mat img, fgmask;
cv::Ptr<cv::BackgroundSubtractor> bg_model;
bool update_bg_model;

Where, img <- smaller image fgmask <- the mask denotes that where motion is happening update_bg_model <- if you want to fixed your background;

step 3: follow this to learn more.

2015-06-20 00:35:23 -0500 received badge  Critic (source)
2015-06-15 01:34:18 -0500 answered a question Xcode6.3.2 __cplusplus notdefine
  1. first follow this to create prefix file (YourPrefixFileName.pch)
  2. add this code to your prefix file

    #ifdef __cplusplus
    #import <opencv2/opencv.hpp>
    #endif
    
    #ifndef YourProjectName_YourPrefixFileName_pch
    #define YourProjectName_YourPrefixFileName_pch
    
    // Include any system framework and library headers here that should be included in all compilation units.
    // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
    
    #endif
    
  3. rename your ViewController's extension from .m (ViewController.m) to .mm (ViewController.mm)
2015-06-15 01:17:17 -0500 answered a question OpenCV setting iOS orientation

(Opencv 3.0) use this class

VideoCamera.h

#import <opencv2/videoio/cap_ios.h>

@protocol VideoCameraDelegate <CvVideoCameraDelegate>
@end

@interface VideoCamera : CvVideoCamera

- (void)updateOrientation;
- (void)layoutPreviewLayer;

@end

VideoCamera.mm

#import "VideoCamera.h"
#define DEGREES_RADIANS(angle) ((angle) / 180.0 * M_PI)
@implementation VideoCamera

 - (void)updateOrientation;
{
    self->customPreviewLayer.bounds = CGRectMake(0, 0, self.parentView.frame.size.width, self.parentView.frame.size.height);
    [self layoutPreviewLayer];
}



 - (void)layoutPreviewLayer;
{
    if (self.parentView != nil)
    {
        CALayer* layer = self->customPreviewLayer;
        CGRect bounds = self->customPreviewLayer.bounds;
        int rotation_angle = 0;

        switch (defaultAVCaptureVideoOrientation) {
            case AVCaptureVideoOrientationLandscapeRight:
                rotation_angle = 270;
                break;
            case AVCaptureVideoOrientationPortraitUpsideDown:
                rotation_angle = 180;
                break;
            case AVCaptureVideoOrientationLandscapeLeft:
                rotation_angle = 90;
                break;
            case AVCaptureVideoOrientationPortrait:
            default:
                break;
        }

        layer.position = CGPointMake(self.parentView.frame.size.width/2., self.parentView.frame.size.height/2.);
        layer.affineTransform = CGAffineTransformMakeRotation( DEGREES_RADIANS(rotation_angle) );
        layer.bounds = bounds;
    }
}

------------- ViewController ----------

ViewController.h

#import "VideoCamera.h"
@interface ViewController : UIViewController<VideoCameraDelegate>{
    VideoCamera* videoCamera;

}
@property (nonatomic, strong) VideoCamera* videoCamera;

@property (strong, nonatomic) IBOutlet UIImageView *mainDisplay;

@end

ViewController.mm

#import "ViewController.h"
@interface ViewController ()

@end
@implementation ViewController

@synthesize videoCamera;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    videoCamera = [[VideoCamera alloc] initWithParentView:_mainDisplay];
    videoCamera.delegate = self;
    videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
    videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPresetHigh;
    videoCamera.defaultAVCaptureVideoOrientation =  AVCaptureVideoOrientationPortrait;
    videoCamera.defaultFPS = 30;
    [videoCamera start];//to start camera preview
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)processImage:(cv::Mat&)image
{
      //process here
}