Ask Your Question

How to show UIImage in processImage:(Mat&)image method

asked 2013-04-07 12:49:23 -0500

Costantino gravatar image

updated 2013-04-07 12:56:52 -0500

Hi all, I want to show a UIImage in processImage:(Mat&)image method, but it does not work. I used this code:

UIImage *imgSegnale = [UIImage imageNamed:@"testImage.png"];
self.imgViewSegnale.image = imgSegnale;

If I add this code in viewDidLod method, it works. Also work if I add this code in a (IBAction) method (using a button). But it don't work if I add this code in processImage:(Mat&)image method.

Any suggestion?

Best regards Costantino

edit retag flag offensive close merge delete


Is this C++ or Java or Python code? Havent seen these structures yet, so it looks kind of weird in the openCV context.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-07 13:22:16 -0500 )edit

This is Objective-C code. I followed this tutorial and in "processImage:(Mat&)image" method I used grabCut() function. So, I converted cv::Mat resulting image in UIImage structure to display it in UIImageView (imgViewSegnale in the code that I wrote before ). Well, the captured image is not displayed. So I tried to display a "static" image (testImage.png) instead of the captured image, but nothing.

(I'm sorry but I do not know English very well and I find it hard to express myself)

Costantino gravatar imageCostantino ( 2013-04-07 13:47:11 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2013-04-11 05:15:02 -0500

ske gravatar image

updated 2013-04-11 05:17:20 -0500


try to get main thread.

dispatch_sync(dispatch_get_main_queue(), ^{
    UIImage *imgSegnale = [UIImage imageNamed:@"testImage.png"];
    [self.imgViewSegnale setImage:imgSegnale];
    [self.view setNeedsDisplay];
edit flag offensive delete link more


It works, thanks a lot.

Costantino gravatar imageCostantino ( 2013-04-12 13:29:47 -0500 )edit

answered 2013-04-07 14:33:43 -0500

AlexanderShishkov gravatar image

Are you sure that processImage method is called? Try to add some output to Console, e.g. through NSLog.

edit flag offensive delete link more


processImage is called. In fact in this method I perform many operations (space color conversion from RGB to HVS, find contour, shape detection and grabCut) and I see result of operations.

Costantino gravatar imageCostantino ( 2013-04-07 15:23:06 -0500 )edit

Question Tools


Asked: 2013-04-07 12:49:23 -0500

Seen: 905 times

Last updated: Apr 11 '13