Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在分析OpenCV中的sampleBuffer时执行错误访问_C++_Objective C_Swift_Opencv_Avfoundation - Fatal编程技术网

C++ 在分析OpenCV中的sampleBuffer时执行错误访问

C++ 在分析OpenCV中的sampleBuffer时执行错误访问,c++,objective-c,swift,opencv,avfoundation,C++,Objective C,Swift,Opencv,Avfoundation,我正在尝试用OpenCV进行实时相机处理。 在AVCaptureVideoDataOutputSampleBufferDelegate的didOutputSampleBuffer方法中,我用sampleBuffer创建了一个矩阵(它工作起来没有任何问题)。但是当执行某些方法时,例如cv::GaussianBlur,应用程序会崩溃,因为“exc_bad_access code=1,address=0x10……”。你知道为什么吗 cv::Mat matrix(bufferHeight, buffer

我正在尝试用OpenCV进行实时相机处理。 在AVCaptureVideoDataOutputSampleBufferDelegate的didOutputSampleBuffer方法中,我用sampleBuffer创建了一个矩阵(它工作起来没有任何问题)。但是当执行某些方法时,例如cv::GaussianBlur,应用程序会崩溃,因为“exc_bad_access code=1,address=0x10……”。你知道为什么吗

cv::Mat matrix(bufferHeight, bufferWidth, CV_8UC4, baseAddress);

cv::GaussianBlur(matrix, matrix, cvSize(5,5), 0); // Crahes here
__编辑:

基址的计算如下所示(在将这些变量传递给objective-c++之前,使用DIDOUTPUTSAMPLEDBUFFER方法在Swift中完成)

____编辑2:

基地址的值
: 0x0000000107790000

像素缓冲区的值

<CVPixelBuffer 0x17413aae0 width=1920 height=1080 pixelFormat=420v iosurface=0x1700039e0 planes=2>
<Plane 0 width=1920 height=1080 bytesPerRow=1920>
<Plane 1 width=960 height=540 bytesPerRow=1920>
<attributes=<CFBasicHash 0x17426e640 [0x1b8d18bb8]>{type = immutable dict, count = 5,
entries =>
    0 : <CFString 0x1b300de28 [0x1b8d18bb8]>{contents = "PixelFormatDescription"} = <CFBasicHash 0x17426a080 [0x1b8d18bb8]>{type = immutable dict, count = 10,
entries =>
    0 : <CFString 0x1b300e088 [0x1b8d18bb8]>{contents = "Planes"} = (
        {
        BitsPerBlock = 8;
        BlackBlock = <10>;
        FillExtendedPixelsCallback = <00000000 00000000 b840aa95 01000000 00000000 00000000>;
    },
        {
        BitsPerBlock = 16;
        BlackBlock = <8080>;
        FillExtendedPixelsCallback = <00000000 00000000 443faa95 01000000 00000000 00000000>;
        HorizontalSubsampling = 2;
        VerticalSubsampling = 2;
    }
)
    2 : <CFString 0x1b300dd68 [0x1b8d18bb8]>{contents = "IOSurfaceOpenGLESFBOCompatibility"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
    3 : <CFString 0x1b300e228 [0x1b8d18bb8]>{contents = "ContainsYCbCr"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
    4 : <CFString 0x1b300dd48 [0x1b8d18bb8]>{contents = "IOSurfaceOpenGLESTextureCompatibility"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
    5 : <CFString 0x1b300e288 [0x1b8d18bb8]>{contents = "ComponentRange"} = <CFString 0x1b300e2a8 [0x1b8d18bb8]>{contents = "VideoRange"}
    6 : <CFString 0x1b300e008 [0x1b8d18bb8]>{contents = "PixelFormat"} = <CFNumber 0xb000000343230762 [0x1b8d18bb8]>{value = +875704438, type = kCFNumberSInt32Type}
    7 : <CFString 0x1b300dd28 [0x1b8d18bb8]>{contents = "IOSurfaceCoreAnimationCompatibility"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
    9 : <CFString 0x1b300e068 [0x1b8d18bb8]>{contents = "ContainsAlpha"} = <CFBoolean 0x1b8d19120 [0x1b8d18bb8]>{value = false}
    10 : <CFString 0x1b300e248 [0x1b8d18bb8]>{contents = "ContainsRGB"} = <CFBoolean 0x1b8d19120 [0x1b8d18bb8]>{value = false}
    11 : <CFString 0x1b300dd88 [0x1b8d18bb8]>{contents = "OpenGLESCompatibility"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
}

    2 : <CFString 0x1b300dbe8 [0x1b8d18bb8]>{contents = "ExtendedPixelsRight"} = <CFNumber 0xb000000000000002 [0x1b8d18bb8]>{value = +0, type = kCFNumberSInt32Type}
    3 : <CFString 0x1b300dbc8 [0x1b8d18bb8]>{contents = "ExtendedPixelsTop"} = <CFNumber 0xb000000000000002 [0x1b8d18bb8]>{value = +0, type = kCFNumberSInt32Type}
    4 : <CFString 0x1b300dba8 [0x1b8d18bb8]>{contents = "ExtendedPixelsLeft"} = <CFNumber 0xb000000000000002 [0x1b8d18bb8]>{value = +0, type = kCFNumberSInt32Type}
    5 : <CFString 0x1b300dc08 [0x1b8d18bb8]>{contents = "ExtendedPixelsBottom"} = <CFNumber 0xb000000000000082 [0x1b8d18bb8]>{value = +8, type = kCFNumberSInt32Type}
}
 propagatedAttachments=<CFBasicHash 0x17426e900 [0x1b8d18bb8]>{type = mutable dict, count = 4,
entries =>
    0 : <CFString 0x1b300d7c8 [0x1b8d18bb8]>{contents = "CVImageBufferYCbCrMatrix"} = <CFString 0x1b300d7e8 [0x1b8d18bb8]>{contents = "ITU_R_709_2"}
    1 : <CFString 0x1b300d928 [0x1b8d18bb8]>{contents = "CVImageBufferTransferFunction"} = <CFString 0x1b300d7e8 [0x1b8d18bb8]>{contents = "ITU_R_709_2"}
    2 : <CFString 0x1b3044fa0 [0x1b8d18bb8]>{contents = "MetadataDictionary"} = <CFBasicHash 0x170077840 [0x1b8d18bb8]>{type = mutable dict, count = 3,
entries =>
    0 : <CFString 0x1b304d100 [0x1b8d18bb8]>{contents = "SNR"} = <CFNumber 0x170036300 [0x1b8d18bb8]>{value = +28.30700356903138370512, type = kCFNumberFloat64Type}
    1 : <CFString 0x1b304b2e0 [0x1b8d18bb8]>{contents = "ExposureTime"} = <CFNumber 0x170033d00 [0x1b8d18bb8]>{value = +0.01000000000000000021, type = kCFNumberFloat64Type}
    2 : <CFString 0x1b304d0e0 [0x1b8d18bb8]>{contents = "SensorID"} = <CFNumber 0xb000000000002472 [0x1b8d18bb8]>{value = +583, type = kCFNumberSInt32Type}
}

    5 : <CFString 0x1b300d8a8 [0x1b8d18bb8]>{contents = "CVImageBufferColorPrimaries"} = <CFString 0x1b300d7e8 [0x1b8d18bb8]>{contents = "ITU_R_709_2"}
}
 nonPropagatedAttachments=<CFBasicHash 0x17426e8c0 [0x1b8d18bb8]>{type = mutable dict, count = 0,
entries =>
}

0:{contents=“PixelFormatDescription”}={type=immutable dict,count=10,
条目=>
0:{contents=“Planes”}=(
{
BitsPerBlock=8;
黑块=;
FillExtendedPixelscalback=;
},
{
BitsPerBlock=16;
黑块=;
FillExtendedPixelscalback=;
水平二次抽样=2;
垂直二次抽样=2;
}
)
2:{contents=“IOSurfaceOpenGLESFBOCompatibility”}={value=true}
3:{contents=“ContainsYCbCr”}={value=true}
4:{contents=“IOSurfaceOpenGLESTextureCompatibility”}={value=true}
5:{contents=“ComponentRange”}={contents=“VideoRange”}
6:{contents=“PixelFormat”}={value=+875704438,type=kCFNumberSInt32Type}
7:{contents=“IOSurfaceCoreAnimationCompatibility”}={value=true}
9:{contents=“ContainsAlpha”}={value=false}
10:{contents=“ContainsRGB”}={value=false}
11:{contents=“OpenGLESCompatibility”}={value=true}
}
2:{contents=“ExtendedPixelsRight”}={value=+0,type=kCFNumberSInt32Type}
3:{contents=“ExtendedPixelsTop”}={value=+0,type=kCFNumberSInt32Type}
4:{contents=“ExtendedPixelsLeft”}={value=+0,type=kCFNumberSInt32Type}
5:{contents=“ExtendedPixelsBottom”}={value=+8,type=kCFNumberSInt32Type}
}
propagatedAttachments={type=mutable dict,count=4,
条目=>
0:{contents=“CVImageBufferYCbCrMatrix”}={contents=“ITU__709_2”}
1:{contents=“CVImageBufferTransferFunction”}={contents=“ITU__709_2”}
2:{contents=“MetadataDictionary”}={type=mutable dict,count=3,
条目=>
0:{contents=“SNR”}={value=+28.30700356903138370512,type=kCFNumberFloat64Type}
1:{contents=“ExposureTime”}={value=+0.01000000000000000021,type=kCFNumberFloat64Type}
2:{contents=“SensorID”}={value=+583,type=kCFNumberSInt32Type}
}
5:{contents=“CVImageBufferColorPrimaries”}={contents=“ITU__709_2”}
}
nonPropagatedAttachments={type=mutable dict,count=0,
条目=>
}

Ah-您的视频数据不是4分量RGBA(或其他),而是“1.5”分量YUV。您应该在YUV中执行模糊,或者更容易地将捕获会话切换到RGBA

YUV是默认格式&其中有两个“平面”

平面0是“Y”,一个1920x1080 8位位图,平面1是“UV”,一个960x540 16位位图(实际上是并排的两个960x540 8位位图,U&V,不确定它们为什么不拆分为3个平面)

在任何情况下,您的代码都需要1920x1080 32位位图,并从Y通道内存的末尾运行

如果您想切换到RGBA,请执行以下操作(我想-我永远记不起iOS使用哪种4组件格式):


如果你有冒险精神,可以对yuv数据进行模糊处理——它比yuv数据小2.667倍,你的代码可能比yuv数据快2.6667倍。

你会遇到什么错误?你能展示一下你是如何计算
基地址的吗?当然!请参阅我的编辑您可以检查
CVPixelBufferLockBaseAddress
CVPixelBufferGetBaseAddress
的返回值吗?您可能不允许写入这些缓冲区。当然!我编辑了我的问题并添加了这些值
<CVPixelBuffer 0x17413aae0 width=1920 height=1080 pixelFormat=420v iosurface=0x1700039e0 planes=2>
<Plane 0 width=1920 height=1080 bytesPerRow=1920>
<Plane 1 width=960 height=540 bytesPerRow=1920>
<attributes=<CFBasicHash 0x17426e640 [0x1b8d18bb8]>{type = immutable dict, count = 5,
entries =>
    0 : <CFString 0x1b300de28 [0x1b8d18bb8]>{contents = "PixelFormatDescription"} = <CFBasicHash 0x17426a080 [0x1b8d18bb8]>{type = immutable dict, count = 10,
entries =>
    0 : <CFString 0x1b300e088 [0x1b8d18bb8]>{contents = "Planes"} = (
        {
        BitsPerBlock = 8;
        BlackBlock = <10>;
        FillExtendedPixelsCallback = <00000000 00000000 b840aa95 01000000 00000000 00000000>;
    },
        {
        BitsPerBlock = 16;
        BlackBlock = <8080>;
        FillExtendedPixelsCallback = <00000000 00000000 443faa95 01000000 00000000 00000000>;
        HorizontalSubsampling = 2;
        VerticalSubsampling = 2;
    }
)
    2 : <CFString 0x1b300dd68 [0x1b8d18bb8]>{contents = "IOSurfaceOpenGLESFBOCompatibility"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
    3 : <CFString 0x1b300e228 [0x1b8d18bb8]>{contents = "ContainsYCbCr"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
    4 : <CFString 0x1b300dd48 [0x1b8d18bb8]>{contents = "IOSurfaceOpenGLESTextureCompatibility"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
    5 : <CFString 0x1b300e288 [0x1b8d18bb8]>{contents = "ComponentRange"} = <CFString 0x1b300e2a8 [0x1b8d18bb8]>{contents = "VideoRange"}
    6 : <CFString 0x1b300e008 [0x1b8d18bb8]>{contents = "PixelFormat"} = <CFNumber 0xb000000343230762 [0x1b8d18bb8]>{value = +875704438, type = kCFNumberSInt32Type}
    7 : <CFString 0x1b300dd28 [0x1b8d18bb8]>{contents = "IOSurfaceCoreAnimationCompatibility"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
    9 : <CFString 0x1b300e068 [0x1b8d18bb8]>{contents = "ContainsAlpha"} = <CFBoolean 0x1b8d19120 [0x1b8d18bb8]>{value = false}
    10 : <CFString 0x1b300e248 [0x1b8d18bb8]>{contents = "ContainsRGB"} = <CFBoolean 0x1b8d19120 [0x1b8d18bb8]>{value = false}
    11 : <CFString 0x1b300dd88 [0x1b8d18bb8]>{contents = "OpenGLESCompatibility"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
}

    2 : <CFString 0x1b300dbe8 [0x1b8d18bb8]>{contents = "ExtendedPixelsRight"} = <CFNumber 0xb000000000000002 [0x1b8d18bb8]>{value = +0, type = kCFNumberSInt32Type}
    3 : <CFString 0x1b300dbc8 [0x1b8d18bb8]>{contents = "ExtendedPixelsTop"} = <CFNumber 0xb000000000000002 [0x1b8d18bb8]>{value = +0, type = kCFNumberSInt32Type}
    4 : <CFString 0x1b300dba8 [0x1b8d18bb8]>{contents = "ExtendedPixelsLeft"} = <CFNumber 0xb000000000000002 [0x1b8d18bb8]>{value = +0, type = kCFNumberSInt32Type}
    5 : <CFString 0x1b300dc08 [0x1b8d18bb8]>{contents = "ExtendedPixelsBottom"} = <CFNumber 0xb000000000000082 [0x1b8d18bb8]>{value = +8, type = kCFNumberSInt32Type}
}
 propagatedAttachments=<CFBasicHash 0x17426e900 [0x1b8d18bb8]>{type = mutable dict, count = 4,
entries =>
    0 : <CFString 0x1b300d7c8 [0x1b8d18bb8]>{contents = "CVImageBufferYCbCrMatrix"} = <CFString 0x1b300d7e8 [0x1b8d18bb8]>{contents = "ITU_R_709_2"}
    1 : <CFString 0x1b300d928 [0x1b8d18bb8]>{contents = "CVImageBufferTransferFunction"} = <CFString 0x1b300d7e8 [0x1b8d18bb8]>{contents = "ITU_R_709_2"}
    2 : <CFString 0x1b3044fa0 [0x1b8d18bb8]>{contents = "MetadataDictionary"} = <CFBasicHash 0x170077840 [0x1b8d18bb8]>{type = mutable dict, count = 3,
entries =>
    0 : <CFString 0x1b304d100 [0x1b8d18bb8]>{contents = "SNR"} = <CFNumber 0x170036300 [0x1b8d18bb8]>{value = +28.30700356903138370512, type = kCFNumberFloat64Type}
    1 : <CFString 0x1b304b2e0 [0x1b8d18bb8]>{contents = "ExposureTime"} = <CFNumber 0x170033d00 [0x1b8d18bb8]>{value = +0.01000000000000000021, type = kCFNumberFloat64Type}
    2 : <CFString 0x1b304d0e0 [0x1b8d18bb8]>{contents = "SensorID"} = <CFNumber 0xb000000000002472 [0x1b8d18bb8]>{value = +583, type = kCFNumberSInt32Type}
}

    5 : <CFString 0x1b300d8a8 [0x1b8d18bb8]>{contents = "CVImageBufferColorPrimaries"} = <CFString 0x1b300d7e8 [0x1b8d18bb8]>{contents = "ITU_R_709_2"}
}
 nonPropagatedAttachments=<CFBasicHash 0x17426e8c0 [0x1b8d18bb8]>{type = mutable dict, count = 0,
entries =>
}
output.videoSettings = [kCVPixelBufferPixelFormatTypeKey as AnyHashable: kCVPixelFormatType_32BGRA]