Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/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++ C++;Opencv AddressSanitizer:未知地址0x000000000040上的SEGV_C++_Opencv_Address Sanitizer - Fatal编程技术网

C++ C++;Opencv AddressSanitizer:未知地址0x000000000040上的SEGV

C++ C++;Opencv AddressSanitizer:未知地址0x000000000040上的SEGV,c++,opencv,address-sanitizer,C++,Opencv,Address Sanitizer,我不能理解这个错误。我正在做一个使用opencv的项目,试图使用hog和svm,灵感来自这个例子:(代码非常相似)。错误在imgs[0]上此函数的第二行。我知道错误就在那里,因为我试图在调用Mat::operator()时,使用cout打印整个图像,您的代码在某个点访问NULL指针。从您发布的代码片段中不清楚出现这种情况的原因,但如果您从调试器运行代码,则应该很明显 删除-fsanize=address时未定义的引用表明更改Makefile后某些代码没有重新编译。你能先清洁一下吗 作为旁注,您还

我不能理解这个错误。我正在做一个使用opencv的项目,试图使用hog和svm,灵感来自这个例子:(代码非常相似)。错误在imgs[0]上此函数的第二行。我知道错误就在那里,因为我试图在调用
Mat::operator()
时,使用
cout打印整个图像,您的代码在某个点访问
NULL
指针。从您发布的代码片段中不清楚出现这种情况的原因,但如果您从调试器运行代码,则应该很明显

删除
-fsanize=address
时未定义的引用表明更改
Makefile
后某些代码没有重新编译。你能先清洁一下吗


作为旁注,您还应该将
-fsanize=address
附加到
LDFLAGS
中(以便在运行库中链接)。

imgs[0]。如果
imgs
始终为空,则size()
是未定义的行为。使用
-g-fn编译时不忽略帧指针,ASAN将为您提供更多信息@DrewDormann我写道我几乎打印了整个矩阵…@Justin,用这些标志我有同样的错误。请注意,
AddressSanitizer无法提供其他信息。
@Justin
-fno-omit-frame-pointer
仅用于获取堆分配的位置,因此在这里没有帮助。Clang文档应该更明确地说明这一点。
void computeHOG(const vector<Mat> &imgs, vector<Mat> &gradients) {
  HOGDescriptor hog;
  hog.winSize = imgs[0].size() / 8 * 8;
  vector<float> descriptors;
  Mat gray;

  for (size_t i = 0; i < imgs.size(); ++i) {
    if (imgs[i].rows >= hog.winSize.height && imgs[i].cols >= hog.winSize.width) {
      Rect r = Rect((imgs[i].rows - hog.winSize.height) / 2,
                    (imgs[i].cols - hog.winSize.width) / 2,
                    hog.winSize.width,
                    hog.winSize.height);

      cvtColor(imgs[i](r), gray, COLOR_BGR2GRAY);
      hog.compute(gray, descriptors, Size(8, 8), Size(0, 0));
      gradients.push_back(Mat(descriptors).t());
    }
  }
}
LDIR=lib
ODIR=build

CXX=g++
CXXFLAGS= -std=c++11 -Wall -Wextra -fsanitize=address -I$(LDIR)

LIBS=-lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videoio

_DEPS=io.hpp hog.hpp
DEPS=$(patsubst %,$(LDIR)/%,$(_DEPS))

_OBJ=main.o io.o hog.o
OBJ=$(patsubst %,$(ODIR)/%,$(_OBJ))

$(ODIR)/%.o: $(LDIR)/%.cpp
    $(CXX) -c -o $@ $< $(CXXFLAGS)

$(ODIR)/%.o: main.cpp $(DEPS)
    $(CXX) -c -o $@ $< $(CXXFLAGS)

main: $(OBJ)
    $(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS)

clean:
    rm -f $(ODIR)/*.o

.PHONY: clean
ASAN:SIGSEGV
=================================================================
==670==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000040 (pc 0x00000040c917 bp 0x7ffe8906f990 sp 0x7ffe8906f980 T0)
    #0 0x40c916 in cv::MatSize::operator()() const (/[...]/opencv-project/main+0x40c916)
    #1 0x40ada0 in computeHOG(std::vector<cv::Mat, std::allocator<cv::Mat> > const&, std::vector<cv::Mat, std::allocator<cv::Mat> >&) (/[...]/opencv-project/main+0x40ada0)
    #2 0x4030df in main (/[...]/opencv-project/main+0x4030df)
    #3 0x7f511da2082f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #4 0x402b48 in _start (/[...]/opencv-project/main+0x402b48)

AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV ??:0 cv::MatSize::operator()() const
==670==ABORTING
main.cpp:(.text+0x20): undefined reference to `__asan_option_detect_stack_use_after_return'
main.cpp:(.text+0x30): undefined reference to `__asan_stack_malloc_4'
build/main.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x970): undefined reference to `__asan_before_dynamic_init'
main.cpp:(.text+0x9d4): undefined reference to `__asan_report_load1'
main.cpp:(.text+0xa14): undefined reference to `__asan_report_store1'
main.cpp:(.text+0xa64): undefined reference to `__asan_report_load1'