cv2.error:Opencv(3.4.3)

s = robot.get_camera_data()
plt.imshow(s)
plt.show()
s_ = robot.get_camera_data()
print (s_.shape)
plt.imshow(s_)
plt.show()
flow = cv2.calcOpticalFlowFarneback(s, s_, None, 0.5, 3, 15, 3, 5, 1.2, 0)

s与s_分别为在仿真环境中采集到的3通道图片数据,但是 运行代码报错,在网上也没有找到相关问题,谢谢大家。

cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\video\src\optflowgf.cpp:1114: error: (-215:Assertion failed) prev0.size() == next0.size() && prev0.channels() == next0.channels() && prev0.channels() == 1 && pyrScale_ < 1 in function 'cv::`anonymous-namespace'::FarnebackOpticalFlowImpl::calc'
此处为代码运行错误。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
请教:尝试opencv2.4.13在linux下编译程序的报错
源代码:#include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/core/core.hpp> using namespace cv; int main() { VideoCapture cap(0); if(!cap.isOpened()) { return -1; } Mat frame; bool stop = false; while(!stop) { cap.read(frame); imshow("Video",frame); if(waitKey(30)==27) //Esc键退出 { stop = true; } } return 0; } 报错:~$ g++ -o opencvq opencv.cpp /tmp/ccQJKVIi.o: In function `main': opencv.cpp:(.text+0x29): undefined reference to `cv::VideoCapture::VideoCapture(int)' opencv.cpp:(.text+0x38): undefined reference to `cv::VideoCapture::isOpened() const' opencv.cpp:(.text+0x80): undefined reference to `cv::VideoCapture::read(cv::Mat&)' opencv.cpp:(.text+0xf9): undefined reference to `cv::Mat::ones(cv::Size_<int>, int)' opencv.cpp:(.text+0x146): undefined reference to `cv::VideoCapture::read(cv::Mat&)' opencv.cpp:(.text+0x33d): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' opencv.cpp:(.text+0x356): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' opencv.cpp:(.text+0x36f): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' opencv.cpp:(.text+0x3a1): undefined reference to `cv::addWeighted(cv::_InputArray const&, double, cv::_InputArray const&, double, double, cv::_OutputArray const&, int)' opencv.cpp:(.text+0x3ba): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' opencv.cpp:(.text+0x3fd): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)' opencv.cpp:(.text+0x425): undefined reference to `cv::waitKey(int)' opencv.cpp:(.text+0x489): undefined reference to `cv::VideoCapture::~VideoCapture()' opencv.cpp:(.text+0x51a): undefined reference to `cv::VideoCapture::~VideoCapture()' /tmp/ccQJKVIi.o: In function `cv::Mat::~Mat()': opencv.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)' /tmp/ccQJKVIi.o: In function `cv::Mat::release()': opencv.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference to `cv::Mat::deallocate()' /tmp/ccQJKVIi.o: In function `cv::Mat::operator()(cv::Rect_<int> const&) const': opencv.cpp:(.text._ZNK2cv3MatclERKNS_5Rect_IiEE[_ZNK2cv3MatclERKNS_5Rect_IiEE]+0x27): undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)' collect2: error: ld returned 1 exit status 第一次使用,在此请教各位前辈,谢谢了
图像分类OpenCV中svm使用报错
参考代码:https://blog.csdn.net/xq920831/article/details/85052318 第123行 用我自己的图片集的时候会报错: cv2.error: OpenCV(3.4.1) C:\projects\opencv-python\opencv\modules\ml\src\data.cpp:298: error: (-215) (layout == ROW_SAMPLE && responses.rows == nsamples) || (layout == COL_SAMPLE && responses.cols == nsamples) in function cv::ml::TrainDataImpl::setData 有人能帮帮我吗
opencv hello.obj : error LNK2001: unresolved external symbol _cvNamedWindow
使用的是vs2012 ultimate 和opencv2.4.2,配置基本成功,配置情况贴在后面 源程序如下: #include <cv.h> #include <highgui.h> //#pragma comment(lib,"cv.lib") //#pragma comment(lib,"highgui.lib") int main() { cvNamedWindow("my window",1); return 0; } 环境配置都是正常的: 在环境变量中配置:D:\Program Files (x86)\opencv2.4.2\opencv\build\x64\vc10\bin;D:\Program Files (x86)\opencv2.4.2\opencv\build\common\tbb\intel64\vc10 在vc++包含目录中配置 库目录中配置 连接器的附加依赖项中配置如下: opencv_calib3d242.lib opencv_contrib242.lib opencv_core242.lib opencv_features2d242.lib opencv_flann242.lib opencv_gpu242.lib opencv_haartraining_engine.lib opencv_highgui242.lib opencv_imgproc242.lib opencv_legacy242.lib opencv_ml242.lib opencv_nonfree242.lib opencv_objdetect242.lib opencv_photo242.lib opencv_stitching242.lib opencv_ts242.lib opencv_video242.lib opencv_videostab242.lib 当然debug和release都进行了如此的配置,debug下多一个字母d 以前也是如此配置,基本成功,但是这次始终成功不了,总是出现问题如下: hello.obj : error LNK2001: unresolved external symbol _cvNamedWindow 网上找了很多种解决方案都不奏效: 1说连接器和库不匹配 2说没有cv.lib 和higugui.lib几个文件,所以添加了 #pragma comment(lib,"cv.lib") #pragma comment(lib,"highgui.lib") 但还是运行不成功,求大神帮忙啊!!
Unrecognized or unsupported array type in function 'cvGetMat'问题
``` import numpy as np import cv2 img = cv2.imread('messi_2.jpg') mask = cv2.imread('mask2.png',0) dst = cv2.inpaint(img,mask,3,cv2.INPAINT_TELEA) cv2.imshow('dst',dst) cv2.waitKey(0) cv2.destroyAllWindows() ``` (base) C:\Users\lenovo>D:/anaconda/python.exe e:/Desktop/test/test.py Traceback (most recent call last): File "e:/Desktop/test/test.py", line 7, in <module> dst = cv2.inpaint(img,mask,3,cv2.INPAINT_TELEA) cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\core\src\array.cpp:2492: error: (-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type in function 'cvGetMat' 最终结果这样,哪里错了啊
opencv运行的时候报错,求解决办法
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 代码运行这一部分的时候经常不定期的发出这种错误 cv2.error: C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:11111: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor 有没有什么好的解决办法呢
python使用opencv处理视频流调用cv2.resizeWindow方法报错?
错误信息如下: Traceback (most recent call last): File "./tools/test.py", line 36, in <module> cv2.resizeWindow("enhanced", 640, 360); cv2.error: OpenCV(4.1.0) /io/opencv/modules/highgui/src/window_QT.cpp:592: error: (-27:Null pointer) NULL guiReceiver (please create a window) in function 'cvResizeWindow' 代码: ``` # -*- coding: utf-8 -*- import PIL import cv2 if __name__ == '__main__': writeVideo_flag = True video_src = "rtsp://admin:Admin123@85.18.13.222" video_capture = cv2.VideoCapture(video_src) source_file = '/approot1/ioth/ai/tf-faster-rcnn-master' print(video_capture.isOpened()) if writeVideo_flag: # 将检测的视频结果输出到output.avi,detection.txt # Define the codec and create VideoWriter object w = int(video_capture.get(3)) print(w) h = int(video_capture.get(4)) print(h) fourcc = cv2.VideoWriter_fourcc(*'MJPG') out = cv2.VideoWriter(source_file + '/img/output.avi', fourcc, 15, (w, h)) list_file = open(source_file + '/img/detection.txt', 'w') frame_index = -1 fps = 0.0 fpscount = 0 #while True: ret, frame = video_capture.read() # frame shape 640*480*3 print(frame) while True: if ret == True: #窗口可以随意调整大小 #这行报错 cv2.resizeWindow("detect Inout", 640, 360); fpscount += 1 else: break; if fpscount % 1 == 0: image = PIL.Image.fromarray(frame) ```
OPencv使用下cvtColor 出错
环境:树莓派3 raspberry 代码片段: import cv2 import numpy as np cap = cv2.VideoCapture(0) faceCasecade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") while(True): ret,frame = cap.read() gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) faces = faceCascade.detectMultiscale( gray, scaleFactor=1.2, minNeighbors = 5, minSize = (30, 30) ) print("Found {0} faces!".format(len(faces))) for(x, y, w, h) in faces: cv2.rectangele(frame,(x,y),(x+w,y+h),(0,255,0),2) cv.inshow('frame',frame) if cv2.waitKey(1)& 0xFF ==ord('q'): break cap.release() cv2.destroyAllwindows() 报错: Traceback (most recent call last): File "/home/pi/Desktop/OPenCV/live.py", line 11, in <module> gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(3.4.3) /home/pi/opencv-3.4.3/modules/imgproc/src/color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor' 如何解决
谁能帮忙看一下OpenCV 3.4.1源码的类型转换编译错误?
环境: 1. Ubuntu 12.04 LTS 2. cmake 3.5.1 3. OpenCV 3.4.1源码 4. Arm Cortex-A7 NXP i.MX6Q 5. 已经sudo为root 执行过程 cd opencv-3.4.1 mkdir build cd build cmakd -D CMAKE_BUILD_TYPE=Relase -D CMAKE_INSTALL_PREFIX=/usr/local .. make make install 出错提示: [ 0%] Built target gen-pkgconfig [ 9%] Built target libwebp [ 14%] Built target IlmImf [ 20%] Built target libprotobuf [ 23%] Built target carotene_objs [ 24%] Built target tegra_hal [ 24%] Built target opencv_ts_pch_dephelp [ 24%] Built target pch_Generate_opencv_ts [ 25%] Built target opencv_core_pch_dephelp [ 25%] Built target pch_Generate_opencv_core [ 31%] Built target opencv_core [ 31%] Built target opencv_imgproc_pch_dephelp [ 31%] Built target pch_Generate_opencv_imgproc [ 31%] Building CXX object modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/smooth.cpp.o /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp: In function ‘void cv::vlineSmooth1N(const FT* const*, const FT*, int, ET*, int) [with ET = unsigned char, FT = {anonymous}::ufixedpoint16]’: /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp:2676:31: error: conversion from ‘{anonymous}::ufixedpoint32’ to ‘cv::uint8_t {aka unsigned char}’ is ambiguous /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp:2676:31: note: candidates are: /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:223:22: note: {anonymous}::ufixedpoint32::operator float() const /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:222:22: note: {anonymous}::ufixedpoint32::operator double() const /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:221:22: note: {anonymous}::ufixedpoint32::operator ET() const [with ET = unsigned char] /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp: In function ‘void cv::vlineSmooth1N1(const FT* const*, const FT*, int, ET*, int) [with ET = unsigned char, FT = {anonymous}::ufixedpoint16]’: /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp:2693:24: error: conversion from ‘const {anonymous}::ufixedpoint16’ to ‘cv::uint8_t {aka unsigned char}’ is ambiguous /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp:2693:24: note: candidates are: /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:289:22: note: {anonymous}::ufixedpoint16::operator float() const /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:288:22: note: {anonymous}::ufixedpoint16::operator double() const /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:287:22: note: {anonymous}::ufixedpoint16::operator ET() const [with ET = unsigned char] /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp: In function ‘void cv::vlineSmooth3N(const FT* const*, const FT*, int, ET*, int) [with ET = unsigned char, FT = {anonymous}::ufixedpoint16]’: /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp:2740:71: error: conversion from ‘{anonymous}::ufixedpoint32’ to ‘cv::uint8_t {aka unsigned char}’ is ambiguous /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp:2740:71: note: candidates are: /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:223:22: note: {anonymous}::ufixedpoint32::operator float() const /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:222:22: note: {anonymous}::ufixedpoint32::operator double() const /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:221:22: note: {anonymous}::ufixedpoint32::operator ET() const [with ET = unsigned char] /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp: In function ‘void cv::vlineSmooth5N(const FT* const*, const FT*, int, ET*, int) [with ET = unsigned char, FT = {anonymous}::ufixedpoint16]’: /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp:2816:109: error: conversion from ‘{anonymous}::ufixedpoint32’ to ‘cv::uint8_t {aka unsigned char}’ is ambiguous /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp:2816:109: note: candidates are: /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:223:22: note: {anonymous}::ufixedpoint32::operator float() const /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:222:22: note: {anonymous}::ufixedpoint32::operator double() const /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:221:22: note: {anonymous}::ufixedpoint32::operator ET() const [with ET = unsigned char] /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp: In function ‘void cv::vlineSmooth(const FT* const*, const FT*, int, ET*, int) [with ET = unsigned char, FT = {anonymous}::ufixedpoint16]’: /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp:2919:18: error: conversion from ‘{anonymous}::ufixedpoint32’ to ‘cv::uint8_t {aka unsigned char}’ is ambiguous /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp:2914:23: note: candidates are: /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:223:22: note: {anonymous}::ufixedpoint32::operator float() const /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:222:22: note: {anonymous}::ufixedpoint32::operator double() const /home/linaro/opencv-3.4.1/modules/imgproc/src/fixedpoint.inl.hpp:221:22: note: {anonymous}::ufixedpoint32::operator ET() const [with ET = unsigned char] make[2]: *** [modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/smooth.cpp.o] Error 1 make[1]: *** [modules/imgproc/CMakeFiles/opencv_imgproc.dir/all] Error 2 make: *** [all] Error 2 说明: 关键之处是 /home/linaro/opencv-3.4.1/modules/imgproc/src/smooth.cpp:2919:18: error: conversion from ‘{anonymous}::ufixedpoint32’ to ‘cv::uint8_t {aka unsigned char}’ is ambiguous 类型转换错误。 请教各位大侠,这个错误出在哪里,如何解决呢? 谢谢!
YOLO v3 OpenCV-3.4.1
balbal..... 下载完weight后,在终端输入: ./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg 我是根据网上Yolo v3教程一步一步来的,装了最新的opencv,发现如下问题: 104 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256 1.595 BFLOPs 105 conv 255 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 255 0.353 BFLOPs 106 yolo Loading weights from yolov3.weights...Done! data/dog.jpg: Predicted in 0.045922 seconds. dog: 99% truck: 92% bicycle: 99% OpenCV(3.4.1) Error: Assertion failed ((flags & FIXED_TYPE) != 0) in type, file /home/kiraq/home/installation/opencv-3.4.1/modules/core/src/matrix_wrap.cpp, line 807 terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(3.4.1) /home/kiraq/home/installation/opencv-3.4.1/modules/core/src/matrix_wrap.cpp:807: error: (-215) (flags & FIXED_TYPE) != 0 in function type Aborted (core dumped) 请问如何解决?
我在使用Python对图像进行二值化的时候,用如下的代码却出现了这样的错误,求教?????????
代码:import cv2 gaosi = cv2.adaptiveThreshold(huidu, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 5, 7) io.imshow(gaosi)# 错误:error: OpenCV(3.4.1) C:\Miniconda3\conda-bld\opencv-suite_1533128839831\work\modules\imgproc\src\thresh.cpp:1524: error: (-215) src.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3)) in function cv::adaptiveThreshold
QT opencv C++ Android编译问题
最近想把windows下写好的opencv代码移植到Android平台上运行,于是搭建了一个QT for Android的编译环境,然后把代码放到QT里面编译。 刚开始用-Desktop_Qt_5_4_1_MinGW_32bit编译运行正常,可是把编译器换成Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_1之后就就报错,在网上查了好几天都没有找到解决方案。 有没有哪位大神知道的,帮帮忙,在下不胜感激!! 以下是关键的代码部分: .pro文件: INCLUDEPATH += E:\opencv\build\include\opencv2\ E:\opencv\build\include\opencv\ E:\opencv\build\include LIBS += E:\opencv_cmake\lib\libopencv_core249.dll.a\ E:\opencv_cmake\lib\libopencv_highgui249.dll.a\ E:\opencv_cmake\lib\libopencv_imgproc249.dll.a\ E:\opencv_cmake\lib\libopencv_calib3d249.dll.a\ E:\opencv_cmake\lib\libopencv_contrib249.dll.a\ E:\opencv_cmake\lib\libopencv_features2d249.dll.a\ E:\opencv_cmake\lib\libopencv_flann249.dll.a\ E:\opencv_cmake\lib\libopencv_gpu249.dll.a\ E:\opencv_cmake\lib\libopencv_legacy249.dll.a\ E:\opencv_cmake\lib\libopencv_ml249.dll.a\ E:\opencv_cmake\lib\libopencv_objdetect249.dll.a\ E:\opencv_cmake\lib\libopencv_video249.dll.a 包含的opencv头文件: #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> opencv代码部分 image = cv::imread("./1.jpg"); if(!image.data) { QMessageBox msgBox; msgBox.setText(tr("image data is null")); msgBox.exec(); } else { cv::cvtColor(image,image,CV_BGR2RGB); img = QImage((const unsigned char*)(image.data),image.cols,image.rows, image.cols*image.channels(), QImage::Format_RGB888); ui->label->clear(); ui->label->setPixmap(QPixmap::fromImage(img)); //ui->processPushButton->setEnabled(true); ui->label->resize(ui->label->pixmap()->size()); } 报错情况: ![图片说明](https://img-ask.csdn.net/upload/201607/28/1469671885_529743.png) E:\opencv\build\include\opencv2\core\mat.hpp:278: error: undefined reference to `cv::fastFree(void*)' E:\opencv\build\include\opencv2\core\mat.hpp:298: error: undefined reference to `cv::Mat::copySize(cv::Mat const&)' E:\opencv\build\include\opencv2\core\mat.hpp:367: error: undefined reference to `cv::Mat::deallocate()' E:\QT_Work\build-testAndroid-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_1-Debug\mainwindow.obj:-1: In function `cv::Mat::operator=(cv::Mat const&)': E:\QT_Work\build-testAndroid-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_1-Debug\mainwindow.obj:-1: In function `cv::Mat::release()': E:\QT_Work\testAndroid\mainwindow.cpp:28: error: undefined reference to `cv::imread(std::string const&, int)'
opencv3.4 加载tensorflow模型 net.forward()总是报错?
OpenCV Error: Assertion failed (!_aspectRatios.empty(), _minSize > 0) in cv::dnn::PriorBoxLayerImpl::PriorBoxLayerImpl, file C:\build\master_winpack-build-win64-vc14\opencv\modules\dnn\src\layers\prior_box_layer.cpp, line 207 C:\build\master_winpack-build-win64-vc14\opencv\modules\dnn\src\layers\prior_box_layer.cpp:207: error: (-215) !_aspectRatios.empty(), _minSize > 0 in function cv::dnn::PriorBoxLayerImpl::PriorBoxLayerImpl
为什么Opencv3.4.0使用make编译时出现错误?
环境:Debian(Raspiberry Pi Buster) cmake version: 3.0.2 gcc version: 8.2.0 python version: 3.7.2 make version: 4.2.1 本来计划用opencv基于python进行图像辨别 在使用cmake配置完成后使用make命令编译: ``` sudo make ``` 编译到大约90%时,出现如下错误: ``` #这是之前很多条控制台信息中的warning warning: cast between incompatible function types from ‘PyObject* (*)(PyObject*, PyObject*, PyObject*)’ {aka ‘_object* (*)(_object*, _object*, _object*)’} to ‘PyCFunction’ {aka ‘_object* (*)(_object*, _object*)’} [-Wcast-function-type] ``` ``` #make错误,退出 make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/build.make:56: modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:21149: modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2 make: *** [Makefile:138: all] Error 2 ``` 如图(图1中使用了make -i选项忽略错误,继续编译剩余部分,但open_cv python3没有成功编译): ![图片说明](https://img-ask.csdn.net/upload/201908/11/1565498546_278259.png) (图2显示了make的错误) ![图片说明](https://img-ask.csdn.net/upload/201908/11/1565499335_385379.png) ``` #忽略错误后出现的c++error c++: error: Cmakefiles/opencv_python3.dir/__/src2/cv2.cpp.o No such file or dictionary ``` 在网上看到的编译错误的例子都和这个有所区别,没有能够很好地解决问题。有的说这是gcc编译器的问题 希望各位大佬们能够帮忙分析一下错误的原因,因为我的项目急需配置好opencv,也没有其它更好的替代,谢谢~
opencv3.1.0交叉编译出错
我在给mini2440移植opencv3.1.0的时候,make编译opencv过程中出错了。log如下: CMakeFiles/opencv_perf_core.dir/perf/perf_math.cpp.obj: In function `cv::Mat::~Mat()': perf_math.cpp.text._ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x1c): undefined reference to `__sync_fetch_and_add_4' CMakeFiles/opencv_perf_core.dir/perf/perf_compare.cpp.obj: In function `Size_MatType_CmpType_compare:erfTestBody()': perf_compare.cpp.text._ZN28Size_MatType_CmpType_compare12PerfTestBodyEv+0x30c): undefined reference to `__sync_fetch_and_add_4' perf_compare.cpp.text._ZN28Size_MatType_CmpType_compare12PerfTestBodyEv+0x378): undefined reference to `__sync_fetch_and_add_4' perf_compare.cpp.text._ZN28Size_MatType_CmpType_compare12PerfTestBodyEv+0x3ec): undefined reference to `__sync_fetch_and_add_4' CMakeFiles/opencv_perf_core.dir/perf/perf_compare.cpp.obj: In function `Size_MatType_CmpType_compareScalar:erfTestBody()': perf_compare.cpp.text._ZN34Size_MatType_CmpType_compareScalar12PerfTestBodyEv+0x32c): undefined reference to `__sync_fetch_and_add_4' CMakeFiles/opencv_perf_core.dir/perf/perf_compare.cpp.obj:perf_compare.cpp.text._ZN34Size_MatType_CmpType_compareScalar12PerfTestBodyEv+0x3a0): more undefined references to `__sync_fetch_and_add_4' follow collect2: ld returned 1 exit status make[2]: *** [bin/opencv_perf_core] Error 1 make[1]: *** [modules/core/CMakeFiles/opencv_perf_core.dir/all] Error 2 make: *** [all] Error 2 我用的是Ubuntu14.04,32位虚拟机。 查网上说是CMAKE_C_FLAGS要设为-march=armv4t 可是我安装提示设置了CMAKE_C_FLAGS 和 CMAKE_CXX_FLAGS的值,错误还是没有消失。 我试过了opencv3.1。0和opencv3.2.0了,都会出现这个问题。因为项目需求要用到opencv3 所以只能自己编译最新版,,泪奔 有大神遇到过这个问题吗?
QT5.9+OpenCV3.10_contrib,GitHub上人脸识别找不到face相关类和hpp
调配了很多天的环境,网上说OpenCV3以后face.hpp在contrib扩展包里面,我都配置好之后还是有如下毛病:(之前用的OpenCV2.410也是如下毛病) #如果在头文件加上 ``` #include<opencv2/contrib/contrib.hpp> #include<opencv2/face.hpp> ``` 就会报错 ``` error: opencv2/face.hpp: No such file or directory ``` ## 如果把这个注释掉(依然保留#include<opencv2/contrib/contrib.hpp>) 就会报错 ![图片说明](https://img-ask.csdn.net/upload/201709/13/1505307425_541519.png) 即 face名词空间还是没找到,和face有关的类还是没找到 百度了很深的程度也没有解决,希望有前辈指点一下,很想完成一个人脸识别的功能 下面把代码都贴出来(UI就不放了) 1、pro文件: ``` #------------------------------------------------- # # Project created by QtCreator 2015-11-11T08:11:51 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = face_recognition TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h FORMS += mainwindow.ui INCLUDEPATH+=C:\OpenCV_contrib\include\opencv\ C:\OpenCV_contrib\include\opencv2\ C:\OpenCV_contrib\include LIBS += -LC:/OpenCV_contrib/lib -lopencv_core2410.dll \ -lopencv_highgui2410.dll -lopencv_imgproc2410.dll -lopencv_features2d2410.dll \ -lopencv_calib3d2410.dll \ -lopencv_objdetect2410.dll \ -lopencv_contrib2410.dll ``` MainWindow.h : ``` #ifndef MAINWINDOW_H #define MAINWINDOW_H #include<QMainWindow> #include<QCloseEvent> #include<opencv2/highgui/highgui.hpp> #include<opencv2/imgproc/imgproc.hpp> #include<opencv2/core/core.hpp> #include<opencv2/objdetect/objdetect.hpp> #include<opencv2/contrib/contrib.hpp> //#include<opencv2/face.hpp> #include<iostream> using namespace std; using namespace cv; using namespace face; namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_loadButton_clicked(); void on_testButton_clicked(); void on_regButton_clicked(); void closeEvent(QCloseEvent *e); private: Ui::MainWindow *ui; Ptr<LBPHFaceRecognizer> model; QString fileName,saveXml,saveName,name[10]; }; #endif // MAINWINDOW_H ``` cpp文件: ``` #include "mainwindow.h" #include "ui_mainwindow.h" #include<QDebug> #include<QFileDialog> #include<QPixmap> #include<QFile> #include<QTextStream> //正面,上,下,左,右5张.阉值85.00 MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); saveName = "Names.txt"; saveXml = "att_model.xml"; model = createLBPHFaceRecognizer(); if(QFile::exists(saveXml)&&QFile::exists(saveName)) { model->load(saveXml.toStdString()); QFile file(saveName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream in(&file); QString lineText; while(!in.atEnd()) { lineText = in.readLine(); QString i = lineText.split(":").first(); name[i.toInt()] = lineText.split(":").last(); } } // for(int i=1;i<11;i++) // for(int j=1;j<10;j++) // { // QString file = "att_faces/s%1/%2.pgm"; // images.push_back(imread(file.arg(i).arg(j).toStdString(), CV_LOAD_IMAGE_GRAYSCALE)); // labels.push_back(i); // } // model = createLBPHFaceRecognizer(); // //model->train(images, labels); // //model->save("att_model.xml"); // model->load("att_model.xml"); } MainWindow::~MainWindow() { delete ui; } void MainWindow::closeEvent(QCloseEvent *e) { model->save(saveXml.toStdString()); QFile file(saveName); if(!file.open(QIODevice::WriteOnly|QIODevice::Text)) return; QTextStream out(&file); for(int i=0;i<10;i++) { if(name[i].isEmpty()) continue; out<<i<<":"<<name[i]<<"\n"; } e->accept(); } void MainWindow::on_loadButton_clicked() { fileName = QFileDialog::getOpenFileName(this,tr("选择图片"),tr(".")); if(fileName.isEmpty()) return; ui->showLabel->setPixmap(QPixmap(fileName)); ui->textBrowser->append(tr("打开图片%1").arg(fileName.split("/").last())); } void MainWindow::on_testButton_clicked() { if(fileName.isEmpty()||ui->nameEdit->text().isEmpty()) return; vector<Mat> images; vector<int> labels; images.push_back(imread(fileName.toStdString(),CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(ui->labelBox->value()); name[ui->labelBox->value()] = ui->nameEdit->text(); ui->textBrowser->append(tr("准备训练: 姓名:%1 标签:%2 ...").arg(ui->nameEdit->text()).arg(ui->labelBox->value())); model->update(images,labels); ui->textBrowser->append(tr("训练完成")); } void MainWindow::on_regButton_clicked() { ui->nameLabel->clear(); if(fileName.isEmpty()) return; Mat image = imread(fileName.toStdString(), CV_LOAD_IMAGE_GRAYSCALE); model->setThreshold(ui->doubleSpinBox->value()); ui->textBrowser->append(tr("准备识别Threshold:%1 ...").arg(ui->doubleSpinBox->value())); int result = model->predict(image); ui->textBrowser->append(tr("识别完成")); if(result < 0) ui->nameLabel->setText(tr("无法识别此人")); else ui->nameLabel->setText(tr("%1").arg(name[result])); } ``` main.cpp: #include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
arm-Fedaro 调用opencv 失败
问题如下,请问怎么解决啊? [toybrick@localhost LSF]$ python3 cv_test Failed to query video capabilities: Inappropriate ioctl for device libv4l2: error getting capabilities: Inappropriate ioctl for device VIDEOIO ERROR: V4L: device /home/toybrick/LSF/input.mp4: Unable to query number of channels mpi: mpp version: Without VCS info mpp_rt: NOT found ion allocator mpp_rt: found drm allocator mpp: deprecated block control, use timeout control instead warning: GStreamer: unable to query duration of stream (/builddir/build/BUILD/opencv-3.4.1/modules/videoio/src/cap_gstreamer.cpp:904) warning: Cannot query video position: status=1 value=1 duration=-1 (/builddir/build/BUILD/opencv-3.4.1/modules/videoio/src/cap_gstreamer.cpp:952)
ubuntu16.04安装opencv时,make不通过该怎么办?
cmake已经完成,情况如下: ``` cmake .. -- Detected version of GNU GCC: 54 (504) -- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found suitable version "1.2.8", minimum required is "1.2.3") -- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.8") -- Checking for module 'gstreamer-base-1.0' -- No package 'gstreamer-base-1.0' found -- Checking for module 'gstreamer-video-1.0' -- No package 'gstreamer-video-1.0' found -- Checking for module 'gstreamer-app-1.0' -- No package 'gstreamer-app-1.0' found -- Checking for module 'gstreamer-riff-1.0' -- No package 'gstreamer-riff-1.0' found -- Checking for module 'gstreamer-pbutils-1.0' -- No package 'gstreamer-pbutils-1.0' found -- Checking for module 'gstreamer-base-0.10' -- No package 'gstreamer-base-0.10' found -- Checking for module 'gstreamer-video-0.10' -- No package 'gstreamer-video-0.10' found -- Checking for module 'gstreamer-app-0.10' -- No package 'gstreamer-app-0.10' found -- Checking for module 'gstreamer-riff-0.10' -- No package 'gstreamer-riff-0.10' found -- Checking for module 'gstreamer-pbutils-0.10' -- No package 'gstreamer-pbutils-0.10' found -- Looking for linux/videodev.h -- Looking for linux/videodev.h - not found -- Looking for linux/videodev2.h -- Looking for linux/videodev2.h - found -- Looking for sys/videoio.h -- Looking for sys/videoio.h - not found -- Checking for module 'libavresample' -- No package 'libavresample' found -- Looking for libavformat/avformat.h -- Looking for libavformat/avformat.h - found -- Looking for ffmpeg/avformat.h -- Looking for ffmpeg/avformat.h - not found -- Checking for module 'libgphoto2' -- No package 'libgphoto2' found -- found IPP (ICV version): 9.0.1 [9.0.1] -- at: /home/quxutao/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx -- CUDA detected: 7.5 -- CUDA NVCC target flags: -gencode;arch=compute_20,code=sm_20;-gencode;arch=compute_20,code=sm_21;-gencode;arch=compute_30,code=sm_30;-gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_30,code=compute_30 -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) -- To enable PlantUML support, set PLANTUML_JAR environment variable or pass -DPLANTUML_JAR=<filepath> option to cmake -- Could NOT find PythonInterp: Found unsuitable version "1.4", but required is at least "2.7" (found /home/quxutao/.virtualenvs/cv/bin/python) -- Could NOT find PythonInterp: Found unsuitable version "1.4", but required is at least "2.6" (found /home/quxutao/.virtualenvs/cv/bin/python) -- Could NOT find PythonInterp: Found unsuitable version "1.4", but required is at least "3.4" (found /home/quxutao/.virtualenvs/cv/bin/python) -- Could NOT find PythonInterp: Found unsuitable version "1.4", but required is at least "3.2" (found /home/quxutao/.virtualenvs/cv/bin/python) -- Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) -- Could NOT find Matlab (missing: MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIRS MATLAB_ROOT_DIR MATLAB_LIBRARIES MATLAB_LIBRARY_DIRS MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN) -- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file -- Caffe: NO -- Protobuf: YES -- Glog: NO -- HDF5: YES -- Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags -- Tesseract: NO -- HDF5: YES -- Build libprotobuf from sources: -- The protocol buffer compiler not found -- Tesseract: NO -- -- General configuration for OpenCV 3.1.0 ===================================== -- Version control: unknown -- -- Platform: -- Host: Linux 4.15.0-47-generic x86_64 -- CMake: 3.5.1 -- CMake generator: Unix Makefiles -- CMake build tool: /usr/bin/make -- Configuration: RELEASE -- -- C/C++: -- Built as dynamic libs?: YES -- C++ Compiler: /usr/bin/c++ (ver 5.4.0) -- C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG -- C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG -- C Compiler: /usr/bin/cc -- C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG -- C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG -- Linker flags (Release): -- Linker flags (Debug): -- Precompiled headers: YES -- Extra dependencies: /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/x86_64-linux-gnu/libtiff.so /usr/lib/x86_64-linux-gnu/libjasper.so /usr/lib/x86_64-linux-gnu/libjpeg.so gtk-3 gdk-3 pangocairo-1.0 pango-1.0 atk-1.0 cairo-gobject cairo gdk_pixbuf-2.0 gio-2.0 gobject-2.0 gthread-2.0 glib-2.0 dc1394 v4l1 v4l2 avcodec-ffmpeg avformat-ffmpeg avutil-ffmpeg swscale-ffmpeg /usr/lib/x86_64-linux-gnu/libbz2.so /usr/lib/x86_64-linux-gnu/hdf5/openmpi/lib/libhdf5.so /usr/lib/x86_64-linux-gnu/libsz.so /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/x86_64-linux-gnu/libdl.so /usr/lib/x86_64-linux-gnu/libm.so dl m pthread rt cudart nppc nppi npps cufft -L/usr/lib/x86_64-linux-gnu -- 3rdparty dependencies: libwebp IlmImf libprotobuf -- -- OpenCV modules: -- To be built: cudev core cudaarithm flann hdf imgproc ml reg surface_matching video cudabgsegm cudafilters cudaimgproc cudawarping dnn fuzzy imgcodecs photo shape videoio cudacodec highgui objdetect plot ts xobjdetect xphoto bgsegm bioinspired dpm face features2d line_descriptor saliency text calib3d ccalib cudafeatures2d cudalegacy cudaobjdetect cudaoptflow cudastereo datasets rgbd stereo structured_light superres tracking videostab xfeatures2d ximgproc aruco optflow stitching -- Disabled: world contrib_world -- Disabled by dependency: - -- Unavailable: java python2 python3 viz cvv matlab sfm -- -- GUI: -- QT: NO -- GTK+ 3.x: YES (ver 3.18.9) -- GThread : YES (ver 2.48.2) -- GtkGlExt: NO -- OpenGL support: NO -- VTK support: NO -- -- Media I/O: -- ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8) -- JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver ) -- WEBP: build (ver 0.3.1) -- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54) -- TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.0.6) -- JPEG 2000: /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1) -- OpenEXR: build (ver 1.7.1) -- GDAL: NO -- -- Video I/O: -- DC1394 1.x: NO -- DC1394 2.x: YES (ver 2.2.4) -- FFMPEG: YES -- codec: YES (ver 56.60.100) -- format: YES (ver 56.40.101) -- util: YES (ver 54.31.100) -- swscale: YES (ver 3.1.101) -- resample: NO -- gentoo-style: YES -- GStreamer: NO -- OpenNI: NO -- OpenNI PrimeSensor Modules: NO -- OpenNI2: NO -- PvAPI: NO -- GigEVisionSDK: NO -- UniCap: NO -- UniCap ucil: NO -- V4L/V4L2: Using libv4l1 (ver 1.10.0) / libv4l2 (ver 1.10.0) -- XIMEA: NO -- Xine: NO -- gPhoto2: NO -- -- Parallel framework: pthreads -- -- Other third-party libraries: -- Use IPP: 9.0.1 [9.0.1] -- at: /home/quxutao/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx -- Use IPP Async: NO -- Use VA: NO -- Use Intel VA-API/OpenCL: NO -- Use Eigen: NO -- Use Cuda: YES (ver 7.5) -- Use OpenCL: YES -- Use custom HAL: NO -- -- NVIDIA CUDA -- Use CUFFT: YES -- Use CUBLAS: NO -- USE NVCUVID: NO -- NVIDIA GPU arch: 20 21 30 35 -- NVIDIA PTX archs: 30 -- Use fast math: NO -- -- OpenCL: -- Version: dynamic -- Include path: /home/quxutao/opencv-3.1.0/3rdparty/include/opencl/1.2 -- Use AMDFFT: NO -- Use AMDBLAS: NO -- -- Python 2: -- Interpreter: NO -- -- Python 3: -- Interpreter: NO -- -- Python (for build): NO -- -- Java: -- ant: NO -- JNI: NO -- Java wrappers: NO -- Java tests: NO -- -- Matlab: Matlab not found or implicitly disabled -- -- Documentation: -- Doxygen: NO -- PlantUML: NO -- -- Tests and samples: -- Tests: YES -- Performance tests: YES -- C/C++ Examples: YES -- -- Install path: /usr/local -- -- cvconfig.h is in: /home/quxutao/opencv-3.1.0/build -- ----------------------------------------------------------------- -- -- Configuring done -- Generating done -- Build files have been written to: /home/quxutao/opencv-3.1.0/build ``` 但是make的时候,就报错: ``` make [ 4%] Built target libwebp [ 4%] Built target IlmImf [ 4%] Built target opencv_cudev [ 4%] Built target opencv_core_pch_dephelp [ 4%] Built target pch_Generate_opencv_core [ 4%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o /usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’: /usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope return (char *) memcpy (__dest, __src, __n) + __n; ^ CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:266 (message): Error generating file /home/quxutao/opencv-3.1.0/build/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o modules/core/CMakeFiles/opencv_core.dir/build.make:399: recipe for target 'modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o' failed make[2]: *** [modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o] Error 1 CMakeFiles/Makefile2:2307: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2 Makefile:160: recipe for target 'all' failed make: *** [all] Error 2 ``` 弄了一下午了,没有找到相关的解决办法。我的cuda是7.5,其实不用GPU也可以的,我只是想用KAZE滤波。。。跪求大神帮忙。。。
openCV_python自带的ANN进行手写字体识别,报错。求助
![图片说明](https://img-ask.csdn.net/upload/202001/31/1580479207_695592.png)![图片说明](https://img-ask.csdn.net/upload/202001/31/1580479217_497206.png) 我用python3.6按照《OpenCV3计算机视觉》书上代码进行手写字识别,识别率很低,运行时还报了错:OpenCV(3.4.1) Error: Assertion failed ((type == 5 || type == 6) && inputs.cols == layer_sizes[0]) in cv::ml::ANN_MLPImpl::predict, file C:\projects\opencv-python\opencv\modules\ml\src\ann_mlp.cpp, line 411 ``` 具体代码如下:求大佬指点下 import cv2 import numpy as np import digits_ann as ANN def inside(r1, r2): x1, y1, w1, h1 = r1 x2, y2, w2, h2 = r2 if (x1 > x2) and (y1 > y2) and (x1 + w1 < x2 + w2) and (y1 + h1 < y2 + h2): return True else: return False def wrap_digit(rect): x, y, w, h = rect padding = 5 hcenter = x + w / 2 vcenter = y + h / 2 if (h > w): w = h x = hcenter - (w / 2) else: h = w y = vcenter - (h / 2) return (int(x - padding), int(y - padding), int(w + padding), int(h + padding)) ''' 注意:首次测试时,建议将使用完整的训练数据集,且进行多次迭代,直到收敛 如:ann, test_data = ANN.train(ANN.create_ANN(100), 50000, 30) ''' ann, test_data = ANN.train(ANN.create_ANN(10), 50000, 1) # 调用所需识别的图片,并处理 path = "C:\\Users\\64601\\PycharmProjects\Ann\\images\\numbers.jpg" img = cv2.imread(path, cv2.IMREAD_UNCHANGED) bw = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) bw = cv2.GaussianBlur(bw, (7, 7), 0) ret, thbw = cv2.threshold(bw, 127, 255, cv2.THRESH_BINARY_INV) thbw = cv2.erode(thbw, np.ones((2, 2), np.uint8), iterations=2) image, cntrs, hier = cv2.findContours(thbw.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) rectangles = [] for c in cntrs: r = x, y, w, h = cv2.boundingRect(c) a = cv2.contourArea(c) b = (img.shape[0] - 3) * (img.shape[1] - 3) is_inside = False for q in rectangles: if inside(r, q): is_inside = True break if not is_inside: if not a == b: rectangles.append(r) for r in rectangles: x, y, w, h = wrap_digit(r) cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2) roi = thbw[y:y + h, x:x + w] try: digit_class = ANN.predict(ann, roi)[0] except: print("except") continue cv2.putText(img, "%d" % digit_class, (x, y - 1), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0)) cv2.imshow("thbw", thbw) cv2.imshow("contours", img) cv2.waitKey() cv2.destroyAllWindows() ####### import cv2 import pickle import numpy as np import gzip """OpenCV ANN Handwritten digit recognition example Wraps OpenCV's own ANN by automating the loading of data and supplying default paramters, such as 20 hidden layers, 10000 samples and 1 training epoch. The load data code is taken from http://neuralnetworksanddeeplearning.com/chap1.html by Michael Nielsen """ def vectorized_result(j): e = np.zeros((10, 1)) e[j] = 1.0 return e def load_data(): with gzip.open('C:\\Users\\64601\\PycharmProjects\\Ann\\mnist.pkl.gz') as fp: # 注意版本不同,需要添加传入第二个参数encoding='bytes',否则出现编码错误 training_data, valid_data, test_data = pickle.load(fp, encoding='bytes') fp.close() return (training_data, valid_data, test_data) def wrap_data(): # tr_d数组长度为50000,va_d数组长度为10000,te_d数组长度为10000 tr_d, va_d, te_d = load_data() # 训练数据集 training_inputs = [np.reshape(x, (784, 1)) for x in tr_d[0]] training_results = [vectorized_result(y) for y in tr_d[1]] training_data = list(zip(training_inputs, training_results)) # 校验数据集 validation_inputs = [np.reshape(x, (784, 1)) for x in va_d[0]] validation_data = list(zip(validation_inputs, va_d[1])) # 测试数据集 test_inputs = [np.reshape(x, (784, 1)) for x in te_d[0]] test_data = list(zip(test_inputs, te_d[1])) return (training_data, validation_data, test_data) def create_ANN(hidden=20): ann = cv2.ml.ANN_MLP_create() # 建立模型 ann.setTrainMethod(cv2.ml.ANN_MLP_RPROP | cv2.ml.ANN_MLP_UPDATE_WEIGHTS) # 设置训练方式为反向传播 ann.setActivationFunction( cv2.ml.ANN_MLP_SIGMOID_SYM) # 设置激活函数为SIGMOID,还有cv2.ml.ANN_MLP_IDENTITY,cv2.ml.ANNMLP_GAUSSIAN ann.setLayerSizes(np.array([784, hidden, 10])) # 设置层数,输入784层,输出层10 ann.setTermCriteria((cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 100, 0.1)) # 设置终止条件 return ann def train(ann, samples=10000, epochs=1): # tr:训练数据集; val:校验数据集; test:测试数据集; tr, val, test = wrap_data() for x in range(epochs): counter = 0 for img in tr: if (counter > samples): break if (counter % 1000 == 0): print("Epoch %d: Trained %d/%d" % (x, counter, samples)) counter += 1 data, digit = img ann.train(np.array([data.ravel()], dtype=np.float32), cv2.ml.ROW_SAMPLE, np.array([digit.ravel()], dtype=np.float32)) print("Epoch %d complete" % x) return ann, test def predict(ann, sample): resized = sample.copy() rows, cols = resized.shape if rows != 28 and cols != 28 and rows * cols > 0: resized = cv2.resize(resized, (28, 28), interpolation=cv2.INTER_CUBIC) return ann.predict(np.array([resized.ravel()], dtype=np.float32)) ```
import cv2 error : dll load failed
我的环境: python 3.6.5 windows 2008 r2 enterprise 我通过 ``` pip install opencv-python pip install opencv-contrib-python ``` 安装opencv 然后当我导入cv2的时候却出现了如下的错误 ``` In [2]: import cv2 --------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-2-c8ec22b3e787> in <module>() ----> 1 import cv2 c:\python36\lib\site-packages\cv2\__init__.py in <module>() 1 import importlib 2 ----> 3 from .cv2 import * 4 from .data import * 5 ImportError: DLL load failed: 找不到指定的模块。 ``` 查找了很多的资料我尝试去下载安装C++ Redistributable Package的各个版本并且去更新系统和去https://www.lfd.uci.edu/~gohlke/pythonlibs/上下载对应whl文件来安装仍旧不能解决这个问题,奇怪的是在我的win7上安装opencv然后导入就没有问题,难道是系统的问题?那么我该如何去查找问题的根源并且去解决呢 万分感谢
终于明白阿里百度这样的大公司,为什么面试经常拿ThreadLocal考验求职者了
点击上面↑「爱开发」关注我们每晚10点,捕获技术思考和创业资源洞察什么是ThreadLocalThreadLocal是一个本地线程副本变量工具类,各个线程都拥有一份线程私有的数
win10系统安装教程(U盘PE+UEFI安装)
一、准备工作 u盘,电脑一台,win10原版镜像(msdn官网) 二、下载wepe工具箱  极力推荐微pe(微pe官方下载) 下载64位的win10 pe,使用工具箱制作启动U盘打开软件,   选择安装到U盘(按照操作无需更改) 三、重启进入pe系统   1、关机后,将U盘插入电脑 2、按下电源后,按住F12进入启动项选择(技嘉主板是F12)     选择需要启
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
《奇巧淫技》系列-python!!每天早上八点自动发送天气预报邮件到QQ邮箱
将代码部署服务器,每日早上定时获取到天气数据,并发送到邮箱。 也可以说是一个小人工智障。 思路可以运用在不同地方,主要介绍的是思路。
Nginx 软件层面加强Nginx性能优化的面试问答和解决方案
Nginx 软件层面加强Nginx性能优化的面试问答和解决方案 去年我去爱卡汽车面试PHP,一轮和二轮面的都不错,在三轮面到Nginx的时候很多问题当时不知道怎么回答,确实没有深入学习过,花了一段时间的学习,终于能解答Nginx高性能优化的问题了,10月24号为了获得程序员勋章,发布了半个优化笔记,浏览到了1000+,受到这个鼓舞,我抽时间在仔细整理下关于Nginx性能优化的问题,我们从软件说起。...
【管理系统课程设计】美少女手把手教你后台管理
【文章后台管理系统】URL设计与建模分析+项目源码+运行界面 栏目管理、文章列表、用户管理、角色管理、权限管理模块(文章最后附有源码) 1. 这是一个什么系统? 1.1 学习后台管理系统的原因 随着时代的变迁,现如今各大云服务平台横空出世,市面上有许多如学生信息系统、图书阅读系统、停车场管理系统等的管理系统,而本人家里就有人在用烟草销售系统,直接在网上完成挑选、购买与提交收货点,方便又快捷。 试想,若没有烟草销售系统,本人家人想要购买烟草,还要独自前往药...
11月19日科技资讯|华为明日发布鸿蒙整体战略;京东宣告全面向技术转型;Kotlin 1.3.60 发布
「极客头条」—— 技术人员的新闻圈! CSDN 的读者朋友们早上好哇,「极客头条」来啦,快来看今天都有哪些值得我们技术人关注的重要新闻吧。扫描上方二维码进入 CSDN App 可以收听御姐萌妹 Style 的人工版音频哟。 一分钟速览新闻点! 6G 专家组成员:速率是 5G 的 10 至 100 倍,预计 2030 年商用 雷军:很多人多次劝我放弃WPS,能坚持下来并不是纯粹的商业决定 ...
C语言魔塔游戏
很早就很想写这个,今天终于写完了。 游戏截图: 编译环境: VS2017 游戏需要一些图片,如果有想要的或者对游戏有什么看法的可以加我的QQ 2985486630 讨论,如果暂时没有回应,可以在博客下方留言,到时候我会看到。 下面我来介绍一下游戏的主要功能和实现方式 首先是玩家的定义,使用结构体,这个名字是可以自己改变的 struct gamerole { char n
化繁为简 - 腾讯计费高一致TDXA的实践之路
导语:腾讯计费是孵化于支撑腾讯内部业务千亿级营收的互联网计费平台,在如此庞大的业务体量下,腾讯计费要支撑业务的快速增长,同时还要保证每笔交易不错账。采用最终一致性或离线补...
Python爬虫爬取淘宝,京东商品信息
小编是一个理科生,不善长说一些废话。简单介绍下原理然后直接上代码。 使用的工具(Python+pycharm2019.3+selenium+xpath+chromedriver)其中要使用pycharm也可以私聊我selenium是一个框架可以通过pip下载 pip install selenium -i https://pypi.tuna.tsinghua.edu.cn/simple/ 
Java学习笔记(七十二)—— Cookie
概述 会话技术: 会话:一次会话中包含多次请求和响应 一次会话:浏览器第一次给服务器发送资源请求,会话建立,直到有一方断开为止 功能:在一次会话的范围内的多次请求间,共享数据 方式: 客户端会话技术:Cookie,把数据存储到客户端 服务器端会话技术:Session,把数据存储到服务器端 Cookie 概念:客户端会话技术,将数据存储到客户端 快速入门: 使用步骤: 创建C
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
Java工作4年来应聘要16K最后没要,细节如下。。。
前奏: 今天2B哥和大家分享一位前几天面试的一位应聘者,工作4年26岁,统招本科。 以下就是他的简历和面试情况。 基本情况: 专业技能: 1、&nbsp;熟悉Sping了解SpringMVC、SpringBoot、Mybatis等框架、了解SpringCloud微服务 2、&nbsp;熟悉常用项目管理工具:SVN、GIT、MAVEN、Jenkins 3、&nbsp;熟悉Nginx、tomca
2020年,冯唐49岁:我给20、30岁IT职场年轻人的建议
点击“技术领导力”关注∆  每天早上8:30推送 作者| Mr.K   编辑| Emma 来源| 技术领导力(ID:jishulingdaoli) 前天的推文《冯唐:职场人35岁以后,方法论比经验重要》,收到了不少读者的反馈,觉得挺受启发。其实,冯唐写了不少关于职场方面的文章,都挺不错的。可惜大家只记住了“春风十里不如你”、“如何避免成为油腻腻的中年人”等不那么正经的文章。 本文整理了冯
程序员该看的几部电影
##1、骇客帝国(1999) 概念:在线/离线,递归,循环,矩阵等 剧情简介: 不久的将来,网络黑客尼奥对这个看似正常的现实世界产生了怀疑。 他结识了黑客崔妮蒂,并见到了黑客组织的首领墨菲斯。 墨菲斯告诉他,现实世界其实是由一个名叫“母体”的计算机人工智能系统控制,人们就像他们饲养的动物,没有自由和思想,而尼奥就是能够拯救人类的救世主。 可是,救赎之路从来都不会一帆风顺,到底哪里才是真实的世界?
作为一个程序员,CPU的这些硬核知识你必须会!
CPU对每个程序员来说,是个既熟悉又陌生的东西? 如果你只知道CPU是中央处理器的话,那可能对你并没有什么用,那么作为程序员的我们,必须要搞懂的就是CPU这家伙是如何运行的,尤其要搞懂它里面的寄存器是怎么一回事,因为这将让你从底层明白程序的运行机制。 随我一起,来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说,我们首先就要搞明白它是怎么回事,也就是它的内部构造,当然,CPU那么牛的一个东
@程序员,如何花式构建线程?
作者 |曾建责编 | 郭芮出品 | CSDN(ID:CSDNnews)在项目和业务的开发中,我们难免要经常使用线程来进行业务处理,使用线程可以保证我们的业务在相互处理之间可以保证原子性...
破14亿,Python分析我国存在哪些人口危机!
2020年1月17日,国家统计局发布了2019年国民经济报告,报告中指出我国人口突破14亿。 猪哥的朋友圈被14亿人口刷屏,但是很多人并没有看到我国复杂的人口问题:老龄化、男女比例失衡、生育率下降、人口红利下降等。 今天我们就来分析一下我们国家的人口数据吧! 一、背景 1.人口突破14亿 2020年1月17日,国家统计局发布了 2019年国民经济报告 ,报告中指出:年末中国大陆总人口(包括31个
强烈推荐10本程序员在家读的书
很遗憾,这个鼠年春节注定是刻骨铭心的,新型冠状病毒让每个人的神经都是紧绷的。那些处在武汉的白衣天使们,尤其值得我们的尊敬。而我们这些窝在家里的程序员,能不外出就不外出,就是对社会做出的最大的贡献。 有些读者私下问我,窝了几天,有点颓丧,能否推荐几本书在家里看看。我花了一天的时间,挑选了 10 本我最喜欢的书,你可以挑选感兴趣的来读一读。读书不仅可以平复恐惧的压力,还可以对未来充满希望,毕竟苦难终
Linux自学篇——linux命令英文全称及解释
man: Manual 意思是手册,可以用这个命令查询其他命令的用法。 pwd:Print working directory 显示当前目录 su:Swith user 切换用户,切换到root用户 cd:Change directory 切换目录 ls:List files 列出目录下的文件 ps:Process Status 进程状态 mk
Python实战:抓肺炎疫情实时数据,画2019-nCoV疫情地图
文章目录1. 前言2. 数据下载3. 数据处理4. 数据可视化 1. 前言 今天,群里白垩老师问如何用python画武汉肺炎疫情地图。白垩老师是研究海洋生态与地球生物的学者,国家重点实验室成员,于不惑之年学习python,实为我等学习楷模。先前我并没有关注武汉肺炎的具体数据,也没有画过类似的数据分布图。于是就拿了两个小时,专门研究了一下,遂成此文。 2月6日追记:本文发布后,腾讯的数据源多次变更u
智力题(程序员面试经典)
NO.1  有20瓶药丸,其中19瓶装有1克/粒的药丸,余下一瓶装有1.1克/粒的药丸。给你一台称重精准的天平,怎么找出比较重的那瓶药丸?天平只能用一次。 解法 有时候,严格的限制条件有可能反倒是解题的线索。在这个问题中,限制条件是天平只能用一次。 因为天平只能用一次,我们也得以知道一个有趣的事实:一次必须同时称很多药丸,其实更准确地说,是必须从19瓶拿出药丸进行称重。否则,如果跳过两瓶或更多瓶药
在家远程办公效率低?那你一定要收好这个「在家办公」神器!
相信大家都已经收到国务院延长春节假期的消息,接下来,在家远程办公可能将会持续一段时间。 但是问题来了。远程办公不是人在电脑前就当坐班了,相反,对于沟通效率,文件协作,以及信息安全都有着极高的要求。有着非常多的挑战,比如: 1在异地互相不见面的会议上,如何提高沟通效率? 2文件之间的来往反馈如何做到及时性?如何保证信息安全? 3如何规划安排每天工作,以及如何进行成果验收? ......
作为一个程序员,内存和磁盘的这些事情,你不得不知道啊!!!
截止目前,我已经分享了如下几篇文章: 一个程序在计算机中是如何运行的?超级干货!!! 作为一个程序员,CPU的这些硬核知识你必须会! 作为一个程序员,内存的这些硬核知识你必须懂! 这些知识可以说是我们之前都不太重视的基础知识,可能大家在上大学的时候都学习过了,但是嘞,当时由于老师讲解的没那么有趣,又加上这些知识本身就比较枯燥,所以嘞,大家当初几乎等于没学。 再说啦,学习这些,也看不出来有什么用啊!
2020年的1月,我辞掉了我的第一份工作
其实,这篇文章,我应该早点写的,毕竟现在已经2月份了。不过一些其它原因,或者是我的惰性、还有一些迷茫的念头,让自己迟迟没有试着写一点东西,记录下,或者说是总结下自己前3年的工作上的经历、学习的过程。 我自己知道的,在写自己的博客方面,我的文笔很一般,非技术类的文章不想去写;另外我又是一个还比较热衷于技术的人,而平常复杂一点的东西,如果想写文章写的清楚点,是需要足够...
别低估自己的直觉,也别高估自己的智商
所有群全部吵翻天,朋友圈全部沦陷,公众号疯狂转发。这两周没怎么发原创,只发新闻,可能有人注意到了。我不是懒,是文章写了却没发,因为大家的关注力始终在这次的疫情上面,发了也没人看。当然,我...
Java坑人面试题系列: 包装类(中级难度)
Java Magazine上面有一个专门坑人的面试题系列: https://blogs.oracle.com/javamagazine/quiz-2。 这些问题的设计宗旨,主要是测试面试者对Java语言的了解程度,而不是为了用弯弯绕绕的手段把面试者搞蒙。 如果你看过往期的问题,就会发现每一个都不简单。 这些试题模拟了认证考试中的一些难题。 而 “中级(intermediate)” 和 “高级(ad
Spring Boot 2.x基础教程:使用JdbcTemplate访问MySQL数据库
在第2章节中,我们介绍了如何通过Spring Boot来实现HTTP接口,以及围绕HTTP接口相关的单元测试、文档生成等实用技能。但是,这些内容还不足以帮助我们构建一个动态应用的服务端程序。不论我们是要做App、小程序、还是传统的Web站点,对于用户的信息、相关业务的内容,通常都需要对其进行存储,而不是像第2章节中那样,把用户信息存储在内存中(重启就丢了!)。 对于信息的存储,现在已经有非常非常多...
基于Python的人脸自动戴口罩系统
目录 1、项目背景 2、页面设计 3、器官识别 4、退出系统 1、项目背景 2019年新型冠状病毒感染的肺炎疫情发生以来,牵动人心,举国哀痛,口罩、酒精、消毒液奇货可居。 抢不到口罩,怎么办?作为技术人今天分享如何使用Python实现自动戴口罩系统,来安慰自己,系统效果如下所示: 本系统的实现原理是借助 Dlib模块的Landmark人脸68个关键点检测库轻松识别出人脸五官
这个世界上人真的分三六九等,你信吗?
偶然间,在知乎上看到一个问题 一时间,勾起了我深深的回忆。 以前在厂里打过两次工,做过家教,干过辅导班,做过中介。零下几度的晚上,贴过广告,满脸、满手地长冻疮。   再回首那段岁月,虽然苦,但让我学会了坚持和忍耐。让我明白了,在这个世界上,无论环境多么的恶劣,只要心存希望,星星之火,亦可燎原。   下文是原回答,希望能对你能有所启发。   如果我说,这个世界上人真的分三六九等,
相关热词 c# 识别回车 c#生成条形码ean13 c#子控制器调用父控制器 c# 写大文件 c# 浏览pdf c#获取桌面图标的句柄 c# list反射 c# 句柄 进程 c# 倒计时 线程 c# 窗体背景色
立即提问