Ask Your Question

3DTOPO's profile - activity

2019-06-21 03:16:26 -0600 received badge  Enthusiast
2019-06-19 19:06:58 -0600 asked a question Compiling for iOS using Xcode 11.0 Beta 2

Compiling for iOS using Xcode 11.0 Beta 2 Hello, I am trying to take advantage of Xcode 11's new build iOS apps for the

2019-05-26 16:26:08 -0600 asked a question Contours generating invalid points

Contours generating invalid points I am generating contours the usual way: equalizeHist(inputImage, inputImage); Laplac

2017-05-07 16:40:08 -0600 commented question Understanding Mat::at and implementing as a Shader

Your missing the point - the code does exactly what I want. I am just trying to understand what Mat:at is doing so I can implement the same behavior as a shader. I know opencv isn't used for shaders.

2017-05-07 03:40:46 -0600 asked a question Understanding Mat::at and implementing as a Shader

Hello,

In a prototype I am using mat:at to achieve a desired result. The problem is I need it to run in realtime on iOS and is currently too slow. I started writing a shader to achieve the same result and I have an image bitmap feed to the shader as a 1D array of bytes (RGBRGB...).

This is roughly my code:

//img is a Mat populated with an RGB image
for (int r=1; r< (img.rows-1 * nativeByte); r++) {
    for (int c=1; c < (img.cols-1 * nativeByte); c++) {
        int outputOffsetNew = currentByte * ((img.cols * r) + c); //swapping stuff around is cool
        outputOffsetNew = effectTwoWithByte(outputOffsetNew, totalPixels);
        uchar newPixel = img.at<cv::Vec2b>(outputOffsetNew)[1];
        img.at<cv::Vec3b>(r,c)[1] = newPixel; //replace the G pixel with the newPixel2 value
    }
}

int effectTwoWithByte(int byte, int totalPixels) {
    while (byte > (totalPixels) - 3) {
        byte *= 0.25f;
        if (byte < 0) {
            byte = 0;
        }
    }
    return byte;
}

Where is the source code for mat::at? Is it in mat.inl.hpp? If so, I am not sure which of the functions in there that it is calling. Can anyone explain what exactly mat:at is doing in my above code? If anyone could help explain what it is doing in pseudo code or C code I would very much appreciate it!

For instance, if I had RGB values populated in a 1D uchar array, what column from a 1D uchar array would the above code use for newPixel?

2017-04-19 23:21:11 -0600 asked a question cvCvtColor CFDataGetBytes Crash on iOS

Hello,

I have used the same code successfully with thousands of images, but I got what seems like a freak crash report. I don't know if the issue is reproducible because I have only received a crash report from a user for it.

Any insight why this has worked for thousands of different images, but crashed on one would be greatly appreciated.

This is my method that crashed:

- (IplImage *)CreateGrayIplImageFromUIImage:(UIImage *)image {
    CGImageRef imageRef = image.CGImage;

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    IplImage *iplimage = cvCreateImage(cvSize(image.size.width, image.size.height), IPL_DEPTH_8U, 4);
    CGContextRef contextRef = CGBitmapContextCreate(iplimage->imageData, iplimage->width, iplimage->height, iplimage->depth, iplimage->widthStep, colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault);

    CGContextDrawImage(contextRef, CGRectMake(0, 0, image.size.width, image.size.height), imageRef);
    CGContextRelease(contextRef);
    CGColorSpaceRelease(colorSpace);

    IplImage *ret = cvCreateImage(cvGetSize(iplimage), IPL_DEPTH_8U, 1);
    cvCvtColor(iplimage, ret, CV_RGBA2GRAY);
    cvReleaseImage(&iplimage);

    return ret;
}

The backtrace originates from cvCvtColor. This is a backtrace of the relevant threads:

Thread #10. Crashed: com.apple.root.default-qos
0  libsystem_platform.dylib       0x185fd8dd0 _platform_memmove + 112
1  CoreFoundation                 0x186e2679c CFDataGetBytes + 372
2  CoreFoundation                 0x186e2679c CFDataGetBytes + 372
3  ImageIO                        0x188d35c60 IIOImageRead::getCFDataBytesAtOffset(void*, unsigned long, unsigned long) + 216
4  ImageIO                        0x188d357b4 IIOImageRead::getBytesAtOffset(void*, unsigned long, unsigned long) + 348
5  ImageIO                        0x188bc893c read_fn2(png_struct_def*, unsigned char*, unsigned long) + 116
6  ImageIO                        0x188d66fc0 png_crc_read + 48
7  ImageIO                        0x188d6b178 png_read_IDAT_data + 308
8  ImageIO                        0x188db46a0 _cg_png_read_row + 188
9  ImageIO                        0x188bc87ac     ___ZN13PNGReadPlugin17copyImageBlockSetEP7InfoRecP15CGImageProvider6CGRect6CGSizePK14__CFDictionary_block_invoke + 560
10 libdispatch.dylib              0x185dd6e44 _dispatch_client_callout2 + 16
11 libdispatch.dylib              0x185de9e38 _dispatch_apply_invoke + 164
12 libdispatch.dylib              0x185dd69a0 _dispatch_client_callout + 16
13 libdispatch.dylib              0x185de6bac _dispatch_root_queue_drain + 888
14 libdispatch.dylib              0x185de67d0 _dispatch_worker_thread3 + 124
15 libsystem_pthread.dylib        0x185fdf1d0 _pthread_wqthread + 1096
16 libsystem_pthread.dylib        0x185fded7c start_wqthread + 4

Thread #5. com.apple.root.default-qos
0  TDTPhotoLib                    0x1008ce1d8 cvCvtColor + 61902
1  TDTPhotoLib                    0x10064f588 -[UIImage(OpenCV) equalArea] (UIImage+OpenCV.mm:52)
2  MyApp                         0x10015c098 TDTImageViewController.prepImage() -> () (TDTOptionsViewController.swift:783)
3  TDTPhotoLib                    0x1006a997c TDTCropImageViewController.(renderAspectImage() -> ()).(closure #1) (TDTCropImageViewController.swift:455)
4  libdispatch.dylib              0x185dd69e0 _dispatch_call_block_and_release + 24
5  libdispatch.dylib              0x185dd69a0 _dispatch_client_callout + 16
6  libdispatch.dylib              0x185de50d4 _dispatch_queue_override_invoke + 644
7  libdispatch.dylib              0x185de6a50 _dispatch_root_queue_drain + 540
8  libdispatch.dylib              0x185de67d0 _dispatch_worker_thread3 + 124
9  libsystem_pthread.dylib        0x185fdf1d0 _pthread_wqthread + 1096
10 libsystem_pthread.dylib        0x185fded7c start_wqthread + 4


Thread #8. com.apple.root.default-qos
0  libsystem_kernel.dylib         0x185f18e64 __psynch_mutexwait + 8
1  libsystem_pthread.dylib        0x185fe4c5c _pthread_mutex_lock_wait + 96
2  ImageIO                        0x188d35698 IIOImageRead::getBytesAtOffset(void*, unsigned long, unsigned long) + 64
3  ImageIO                        0x188bc893c read_fn2(png_struct_def*, unsigned char*, unsigned long) + 116
4  ImageIO                        0x188d670f4 png_crc_error + 56
5  ImageIO                        0x188d67048 png_crc_finish + 92
6  ImageIO                        0x188d6b0d4 png_read_IDAT_data + 144
7  ImageIO                        0x188db46a0 _cg_png_read_row + 188
8  ImageIO                        0x188bc87ac ___ZN13PNGReadPlugin17copyImageBlockSetEP7InfoRecP15CGImageProvider6CGRect6CGSizePK14__CFDictionary_block_invoke + 560
9  libdispatch.dylib              0x185dd6e44 _dispatch_client_callout2 + 16
10 libdispatch.dylib              0x185deaa3c _dispatch_apply_invoke_and_wait + 164
11 libdispatch.dylib              0x185dea47c dispatch_apply_f + 828
12 ImageIO                        0x188bc82b4 PNGReadPlugin::copyImageBlockSet(InfoRec*, CGImageProvider*, CGRect, CGSize, __CFDictionary const*) + 3472
13 ImageIO                        0x188bc5c50 PNGReadPlugin::CopyImageBlockSetProc(void*, CGImageProvider*, CGRect, CGSize, __CFDictionary const*) + 192
14 ImageIO                        0x188bcfbbc IIOImageProviderInfo::copyImageBlockSetWithOptions(CGImageProvider*, CGRect, CGSize, __CFDictionary const*) + 632
15 ImageIO                        0x188bcda14 IIOImageProviderInfo::CopyImageBlockSetWithOptions(void*, CGImageProvider*, CGRect, CGSize, __CFDictionary const*) + 340
16 CoreGraphics                   0x1884efef4 img_blocks_create + 264
17 CoreGraphics                   0x1884f7860 img_data_lock + 1872
18 CoreGraphics                   0x1884f70b8 CGSImageDataLock + 176
19 CoreGraphics                   0x1883171c0 ripc_AcquireImage + 756
20 ...
(more)