谁用过python中的第三方库face recognition
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了谁用过python中的第三方库face recognition相关的知识,希望对你有一定的参考价值。
参考技术A 简介该库可以通过python或者命令行即可实现人脸识别的功能。使用dlib深度学习人脸识别技术构建,在户外脸部检测数据库基准(Labeled Faces in the Wild)上的准确率为99.38%。
在github上有相关的链接和API文档。
在下方为提供的一些相关源码或是文档。当前库的版本是v0.2.0,点击docs可以查看API文档,我们可以查看一些函数相关的说明等。
安装配置
安装配置很简单,按照github上的说明一步一步来就可以了。
根据你的python版本输入指令:
pip install face_recognition11
或者
pip3 install face_recognition11
正常来说,安装过程中会出错,会在安装dlib时出错,可能报错也可能会卡在那不动。因为pip在编译dlib时会出错,所以我们需要手动编译dlib再进行安装。
按照它给出的解决办法:
1、先下载下来dlib的源码。
git clone
2、编译dlib。
cd dlib
mkdir build
cd build
cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1
cmake --build1234512345
3、编译并安装python的拓展包。
cd ..
python3 setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA1212
注意:这个安装步骤是默认认为没有GPU的,所以不支持cuda。
在自己手动编译了dlib后,我们可以在python中import dlib了。
之后再重新安装,就可以配置成功了。
根据你的python版本输入指令:
pip install face_recognition11
或者
pip3 install face_recognition11
安装成功之后,我们可以在python中正常import face_recognition了。
编写人脸识别程序
编写py文件:
# -*- coding: utf-8 -*-
#
# 检测人脸
import face_recognition
import cv2
# 读取图片并识别人脸
img = face_recognition.load_image_file("silicon_valley.jpg")
face_locations = face_recognition.face_locations(img)
print face_locations
# 调用opencv函数显示图片
img = cv2.imread("silicon_valley.jpg")
cv2.namedWindow("原图")
cv2.imshow("原图", img)
# 遍历每个人脸,并标注
faceNum = len(face_locations)
for i in range(0, faceNum):
top = face_locations[i][0]
right = face_locations[i][1]
bottom = face_locations[i][2]
left = face_locations[i][3]
start = (left, top)
end = (right, bottom)
color = (55,255,155)
thickness = 3
cv2.rectangle(img, start, end, color, thickness)
# 显示识别结果
cv2.namedWindow("识别")
cv2.imshow("识别", img)
cv2.waitKey(0)
cv2.destroyAllWindows()12345678910111213141516171819202122232425262728293031323334353637381234567891011121314151617181920212223242526272829303132333435363738
注意:这里使用了python-OpenCV,一定要配置好了opencv才能运行成功。
运行结果:
程序会读取当前目录下指定的图片,然后识别其中的人脸,并标注每个人脸。
(使用图片来自美剧硅谷)
编写人脸比对程序
首先,我在目录下放了几张图片:
这里用到的是一张乔布斯的照片和一张奥巴马的照片,和一张未知的照片。
编写程序:
# 识别图片中的人脸
import face_recognition
jobs_image = face_recognition.load_image_file("jobs.jpg");
obama_image = face_recognition.load_image_file("obama.jpg");
unknown_image = face_recognition.load_image_file("unknown.jpg");
jobs_encoding = face_recognition.face_encodings(jobs_image)[0]
obama_encoding = face_recognition.face_encodings(obama_image)[0]
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]
results = face_recognition.compare_faces([jobs_encoding, obama_encoding], unknown_encoding )
labels = ['jobs', 'obama']
print('results:'+str(results))
for i in range(0, len(results)):
if results[i] == True:
print('The person is:'+labels[i])123456789101112131415161718123456789101112131415161718
运行结果:
识别出未知的那张照片是乔布斯的。
摄像头实时识别
代码:
# -*- coding: utf-8 -*-
import face_recognition
import cv2
video_capture = cv2.VideoCapture(1)
obama_img = face_recognition.load_image_file("obama.jpg")
obama_face_encoding = face_recognition.face_encodings(obama_img)[0]
face_locations = []
face_encodings = []
face_names = []
process_this_frame = True
while True:
ret, frame = video_capture.read()
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
if process_this_frame:
face_locations = face_recognition.face_locations(small_frame)
face_encodings = face_recognition.face_encodings(small_frame, face_locations)
face_names = []
for face_encoding in face_encodings:
match = face_recognition.compare_faces([obama_face_encoding], face_encoding)
if match[0]:
name = "Barack"
else:
name = "unknown"
face_names.append(name)
process_this_frame = not process_this_frame
for (top, right, bottom, left), name in zip(face_locations, face_names):
top *= 4
right *= 4
bottom *= 4
left *= 4
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), 2)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left+6, bottom-6), font, 1.0, (255, 255, 255), 1)
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545512345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
识别结果:
我直接在手机上百度了几张图试试,程序识别出了奥巴马。
这个库很cool啊!
CPP 中的 OpenCV 库(特别是文件 letter_recog.cpp)
【中文标题】CPP 中的 OpenCV 库(特别是文件 letter_recog.cpp)【英文标题】:OpenCV Libraries in CPP (Specifically, file letter_recog.cpp) 【发布时间】:2017-09-14 21:56:06 【问题描述】:我只是想从 opencv 库中为 cpp 编译/构建/运行示例代码,当我尝试构建它时遇到了问题。
我已经按照http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html 正确安装了opencv 以及将 opencv 包含文件从框架文件移动到 /usr/local/include/opencv2 的包含中 将框架中的 opencv 包含文件移动到该文件夹中解决了我的大部分问题(未找到 opencv2 文件),但构建文件 letter_recog.cpp 的问题不起作用。通过不工作,我的意思是它有很多构建错误。
文件的代码如下: https://github.com/opencv/opencv/blob/master/samples/cpp/letter_recog.cpp
构建错误如下:
g++ -g -std=c++14 -Wall -Wextra -pedantic -lpthread -o "letter_recog" "letter_recog.cpp" (in directory: /home/courtneymaroney/opencv/samples/cpp)
/tmp/ccUbgW02.o: In function `read_num_class_data(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, cv::Mat*, cv::Mat*)':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:74: undefined reference to `cv::Mat::push_back(cv::Mat const&)'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:77: undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
/tmp/ccUbgW02.o: In function `prepare_train_data(cv::Mat const&, cv::Mat const&, int)':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:100: undefined reference to `cv::Mat::zeros(int, int, int)'
/tmp/ccUbgW02.o: In function `prepare_train_data(cv::Mat const&, cv::Mat const&, int)':
/usr/local/include/opencv2/core/mat.hpp:1110: undefined reference to `cv::noArray()'
/tmp/ccUbgW02.o: In function `prepare_train_data(cv::Mat const&, cv::Mat const&, int)':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:102: undefined reference to `cv::Mat::setTo(cv::_InputArray const&, cv::_InputArray const&)'
/tmp/ccUbgW02.o: In function `prepare_train_data(cv::Mat const&, cv::Mat const&, int)':
/usr/local/include/opencv2/core/mat.hpp:1110: undefined reference to `cv::noArray()'
/tmp/ccUbgW02.o: In function `prepare_train_data(cv::Mat const&, cv::Mat const&, int)':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:106: undefined reference to `cv::Mat::setTo(cv::_InputArray const&, cv::_InputArray const&)'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:110: undefined reference to `cv::noArray()'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:110: undefined reference to `cv::noArray()'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:110: undefined reference to `cv::ml::TrainData::create(cv::_InputArray const&, int, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&)'
/tmp/ccUbgW02.o: In function `test_and_save_classifier(cv::Ptr<cv::ml::StatModel> const&, cv::Mat const&, cv::Mat const&, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/opencv2/ml.hpp:349: undefined reference to `cv::noArray()'
/tmp/ccUbgW02.o: In function `build_rtrees_classifier(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:187: undefined reference to `cv::ml::RTrees::create()'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:208: undefined reference to `cv::sum(cv::_InputArray const&)'
/tmp/ccUbgW02.o: In function `build_boost_classifier(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/opencv2/core/mat.hpp:1110: undefined reference to `cv::noArray()'
/tmp/ccUbgW02.o: In function `build_boost_classifier(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:277: undefined reference to `cv::Mat::setTo(cv::_InputArray const&, cv::_InputArray const&)'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:281: undefined reference to `cv::noArray()'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:281: undefined reference to `cv::noArray()'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:281: undefined reference to `cv::noArray()'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:281: undefined reference to `cv::ml::TrainData::create(cv::_InputArray const&, int, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&)'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:287: undefined reference to `cv::ml::Boost::create()'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:314: undefined reference to `cv::noArray()'
/tmp/ccUbgW02.o: In function `build_mlp_classifier(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:383: undefined reference to `cv::Mat::zeros(int, int, int)'
/tmp/ccUbgW02.o: In function `build_mlp_classifier(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/opencv2/ml.hpp:285: undefined reference to `cv::noArray()'
/usr/local/include/opencv2/ml.hpp:285: undefined reference to `cv::noArray()'
/usr/local/include/opencv2/ml.hpp:284: undefined reference to `cv::noArray()'
/usr/local/include/opencv2/ml.hpp:284: undefined reference to `cv::noArray()'
/tmp/ccUbgW02.o: In function `build_mlp_classifier(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:408: undefined reference to `cv::ml::TrainData::create(cv::_InputArray const&, int, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&)'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:411: undefined reference to `cv::ml::ANN_MLP::create()'
/tmp/ccUbgW02.o: In function `build_knearest_classifier(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:440: undefined reference to `cv::ml::KNearest::create()'
/tmp/ccUbgW02.o: In function `build_nbayes_classifier(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:467: undefined reference to `cv::ml::NormalBayesClassifier::create()'
/tmp/ccUbgW02.o: In function `build_svm_classifier(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:504: undefined reference to `cv::ml::SVM::create()'
/tmp/ccUbgW02.o: In function `main':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:524: undefined reference to `cv::CommandLineParser::CommandLineParser(int, char const* const*, cv::String const&)'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:526: undefined reference to `cv::CommandLineParser::has(cv::String const&) const'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:528: undefined reference to `cv::CommandLineParser::has(cv::String const&) const'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:530: undefined reference to `cv::CommandLineParser::has(cv::String const&) const'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:532: undefined reference to `cv::CommandLineParser::has(cv::String const&) const'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:534: undefined reference to `cv::CommandLineParser::has(cv::String const&) const'
/tmp/ccUbgW02.o:/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:536: more undefined references to `cv::CommandLineParser::has(cv::String const&) const' follow
/tmp/ccUbgW02.o: In function `main':
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:557: undefined reference to `cv::CommandLineParser::~CommandLineParser()'
/home/courtneymaroney/opencv/samples/cpp/letter_recog.cpp:524: undefined reference to `cv::CommandLineParser::~CommandLineParser()'
/tmp/ccUbgW02.o: In function `cv::String::String(char const*)':
/usr/local/include/opencv2/core/cvstd.hpp:618: undefined reference to `cv::String::allocate(unsigned long)'
/tmp/ccUbgW02.o: In function `cv::String::~String()':
/usr/local/include/opencv2/core/cvstd.hpp:660: undefined reference to `cv::String::deallocate()'
/tmp/ccUbgW02.o: In function `cv::Mat::Mat(int, int, int, void*, unsigned long)':
/usr/local/include/opencv2/core/mat.inl.hpp:413: undefined reference to `cv::error(int, cv::String const&, char const*, char const*, int)'
/tmp/ccUbgW02.o: In function `cv::Mat::~Mat()':
/usr/local/include/opencv2/core/mat.inl.hpp:556: undefined reference to `cv::fastFree(void*)'
/tmp/ccUbgW02.o: In function `cv::Mat::row(int) const':
/usr/local/include/opencv2/core/mat.inl.hpp:591: undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Range const&, cv::Range const&)'
/tmp/ccUbgW02.o: In function `cv::Mat::rowRange(int, int) const':
/usr/local/include/opencv2/core/mat.inl.hpp:603: undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Range const&, cv::Range const&)'
/tmp/ccUbgW02.o: In function `cv::Mat::colRange(int, int) const':
/usr/local/include/opencv2/core/mat.inl.hpp:615: undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Range const&, cv::Range const&)'
/tmp/ccUbgW02.o: In function `cv::Mat::create(int, int, int)':
/usr/local/include/opencv2/core/mat.inl.hpp:648: undefined reference to `cv::Mat::create(int, int const*, int)'
/tmp/ccUbgW02.o: In function `cv::Mat::release()':
/usr/local/include/opencv2/core/mat.inl.hpp:667: undefined reference to `cv::Mat::deallocate()'
/tmp/ccUbgW02.o: In function `cv::FileStorage::getFirstTopLevelNode() const':
/usr/local/include/opencv2/core/persistence.hpp:1167: undefined reference to `cv::FileStorage::root(int) const'
/tmp/ccUbgW02.o: In function `cv::FileNode::begin() const':
/usr/local/include/opencv2/core/persistence.hpp:1184: undefined reference to `cv::FileNodeIterator::FileNodeIterator(CvFileStorage const*, CvFileNode const*, unsigned long)'
/tmp/ccUbgW02.o: In function `cv::FileNode::end() const':
/usr/local/include/opencv2/core/persistence.hpp:1185: undefined reference to `cv::FileNode::size() const'
/usr/local/include/opencv2/core/persistence.hpp:1185: undefined reference to `cv::FileNodeIterator::FileNodeIterator(CvFileStorage const*, CvFileNode const*, unsigned long)'
/tmp/ccUbgW02.o: In function `cv::String::String(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/opencv2/core/cvstd.inl.hpp:81: undefined reference to `cv::String::allocate(unsigned long)'
/tmp/ccUbgW02.o: In function `cv::String cv::CommandLineParser::get<cv::String>(cv::String const&, bool) const':
/usr/local/include/opencv2/core/utility.hpp:682: undefined reference to `cv::CommandLineParser::getByName(cv::String const&, bool, int, void*) const'
/tmp/ccUbgW02.o: In function `cv::Mat::Mat<int>(std::vector<int, std::allocator<int> > const&, bool)':
/usr/local/include/opencv2/core/mat.inl.hpp:469: undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
/tmp/ccUbgW02.o: In function `cv::Mat::Mat<double>(std::vector<double, std::allocator<double> > const&, bool)':
/usr/local/include/opencv2/core/mat.inl.hpp:469: undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
/tmp/ccUbgW02.o: In function `cv::Ptr<cv::ml::RTrees> cv::Algorithm::load<cv::ml::RTrees>(cv::String const&, cv::String const&)':
/usr/local/include/opencv2/core.hpp:2972: undefined reference to `cv::FileStorage::FileStorage(cv::String const&, int, cv::String const&)'
/usr/local/include/opencv2/core.hpp:2973: undefined reference to `cv::FileStorage::operator[](cv::String const&) const'
/usr/local/include/opencv2/core.hpp:2974: undefined reference to `cv::ml::RTrees::create()'
/usr/local/include/opencv2/core.hpp:2972: undefined reference to `cv::FileStorage::~FileStorage()'
/usr/local/include/opencv2/core.hpp:2972: undefined reference to `cv::FileStorage::~FileStorage()'
/tmp/ccUbgW02.o: In function `cv::Ptr<cv::ml::Boost> cv::Algorithm::load<cv::ml::Boost>(cv::String const&, cv::String const&)':
/usr/local/include/opencv2/core.hpp:2972: undefined reference to `cv::FileStorage::FileStorage(cv::String const&, int, cv::String const&)'
/usr/local/include/opencv2/core.hpp:2973: undefined reference to `cv::FileStorage::operator[](cv::String const&) const'
/usr/local/include/opencv2/core.hpp:2974: undefined reference to `cv::ml::Boost::create()'
/usr/local/include/opencv2/core.hpp:2972: undefined reference to `cv::FileStorage::~FileStorage()'
/usr/local/include/opencv2/core.hpp:2972: undefined reference to `cv::FileStorage::~FileStorage()'
/tmp/ccUbgW02.o: In function `cv::Ptr<cv::ml::ANN_MLP> cv::Algorithm::load<cv::ml::ANN_MLP>(cv::String const&, cv::String const&)':
/usr/local/include/opencv2/core.hpp:2972: undefined reference to `cv::FileStorage::FileStorage(cv::String const&, int, cv::String const&)'
/usr/local/include/opencv2/core.hpp:2973: undefined reference to `cv::FileStorage::operator[](cv::String const&) const'
/usr/local/include/opencv2/core.hpp:2974: undefined reference to `cv::ml::ANN_MLP::create()'
/usr/local/include/opencv2/core.hpp:2972: undefined reference to `cv::FileStorage::~FileStorage()'
/usr/local/include/opencv2/core.hpp:2972: undefined reference to `cv::FileStorage::~FileStorage()'
/tmp/ccUbgW02.o: In function `cv::Ptr<cv::ml::SVM> cv::Algorithm::load<cv::ml::SVM>(cv::String const&, cv::String const&)':
/usr/local/include/opencv2/core.hpp:2972: undefined reference to `cv::FileStorage::FileStorage(cv::String const&, int, cv::String const&)'
/usr/local/include/opencv2/core.hpp:2973: undefined reference to `cv::FileStorage::operator[](cv::String const&) const'
/usr/local/include/opencv2/core.hpp:2974: undefined reference to `cv::ml::SVM::create()'
/usr/local/include/opencv2/core.hpp:2972: undefined reference to `cv::FileStorage::~FileStorage()'
/usr/local/include/opencv2/core.hpp:2972: undefined reference to `cv::FileStorage::~FileStorage()'
collect2: error: ld returned 1 exit status
Compilation failed.
我正在为 Ubuntu 16.04 使用一个名为“Geany”的 IDE。
granny 的编译/构建命令如下: 编译: g++ -std=c++14 -Wall -c "%f" 建造: g++ -g -std=c++14 -Wall -Wextra -pedantic -lpthread -o "%e" "%f"
我在互联网上寻找可能的解决方案。似乎有些人遇到了这个问题,但还没有人找到解决方案,或者至少没有人为此分享过解决方案。
echo $(pkg-config --libs opencv) 的输出 [我对其进行了格式化以使其更具可读性]:
echo $(pkg-config --libs opencv)
/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so
-lopencv_calib3d
/usr/lib/x86_64-linux-gnu/libopencv_contrib.so
-lopencv_contrib
/usr/lib/x86_64-linux-gnu/libopencv_core.so
-lopencv_core
/usr/lib/x86_64-linux-gnu/libopencv_features2d.so
-lopencv_features2d
/usr/lib/x86_64-linux-gnu/libopencv_flann.so
-lopencv_flann
/usr/lib/x86_64-linux-gnu/libopencv_gpu.so
-lopencv_gpu
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so
-lopencv_highgui
/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so
-lopencv_imgproc
/usr/lib/x86_64-linux-gnu/libopencv_legacy.so
-lopencv_legacy
/usr/lib/x86_64-linux-gnu/libopencv_ml.so
-lopencv_ml
/usr/lib/x86_64-linux-gnu/libopencv_objdetect.so
-lopencv_objdetect
/usr/lib/x86_64-linux-gnu/libopencv_ocl.so
-lopencv_ocl
/usr/lib/x86_64-linux-gnu/libopencv_photo.so
-lopencv_photo
/usr/lib/x86_64-linux-gnu/libopencv_stitching.so
-lopencv_stitching
/usr/lib/x86_64-linux-gnu/libopencv_superres.so
-lopencv_superres
/usr/lib/x86_64-linux-gnu/libopencv_ts.so
-lopencv_ts
/usr/lib/x86_64-linux-gnu/libopencv_video.so
-lopencv_video
/usr/lib/x86_64-linux-gnu/libopencv_videostab.so
-lopencv_videostab
【问题讨论】:
你必须链接你正在使用的 OpenCV 库。 我试过了。它消除了一些问题,但它说找不到 imgcodecs。还有没有更快的方法或命令行每次都可以轻松完成? "没有人找到解决方案" -- 知道如何编译和链接你的代码是一项基本技能,我无法想象任何有能力的人觉得有必要为每个人写一篇单独的文章网络上散布着一段代码。您只需要了解一般原则,以及如何应用它们。 |您使用的是哪个版本的 OpenCV? 2.4 分支中可用的模块与 3.x 分支中的模块不同。 |关于命令行问题——我更喜欢使用 CMake。我建议阅读它是什么以及如何使用它。 为了详细说明最后一部分,为了编译重要的代码,您通常使用一些其他程序来驱动编译,并为它提供一些您想要构建的内容以及如何构建的描述。在类 unix 系统上,它通常是一个名为“make”的程序(对于简单的事情,您可以编写一个 shell 脚本)。但是,编写 makefile 有点痛苦,因此在此之上还有一个抽象层次——CMake 就是这样一种情况。它允许您以更一般的方式描述事物,然后生成使用特定工具包构建代码所需的文件。 这是 OpenCV 3.0 【参考方案1】:我不明白您是如何在系统上安装opencv
的,如果您真的手动复制了系统路径中的标头,那么我可能不想知道。另外我对IDE过敏,还是用更友好的终端吧。
通常最好的选择是在您的存储库中安装一个。在您的情况下(从您问题的标签来看,它显示为 ubuntu 16.10):
sudo apt update
sudo apt install libopencv-dev
这将修复有助于编译的pkg-config
文件。 (免责声明手动复制的标头的存在可能会干扰安装过程。如果您将它们放在/usr/include
中,我建议您在发出这两个命令之前将其删除)
现在对于letter_recog.cpp
的编译,以这种方式调用编译器就足够了:
g++ $(pkg-config --cflags --libs opencv) letter_recog.cpp -o letter_recog
如果你愿意,你也可以添加你的标志(-Wall -pedantic
等),但我建议你检查pkg-config
的作用:
echo $(pkg-config --cflags opencv)
echo $(pkg-config --libs opencv)
尤其是第二个是您显然错过的(要链接的库)。
最后,为了在 Geany 中进行修复,我怀疑您必须放置以下内容:
g++ -std=c++14 -Wall $(pkg-config --cflags opencv) -c "%f"
和
g++ -g -std=c++14 -Wall -Wextra -pedantic -lpthread $(pkg-config --libs opencv) -o "%e" "%f"
但是这个解决方案是有问题的(比如-lpthread
而不是-pthread
;而且你不需要它们来编写代码)。
长话短说:听听 Dan Mašek 的第一条评论:他是对的。
(抱歉打错了,我的保险丝很晚)
【讨论】:
谢谢。会尝试一下,然后回复你们。 接下来的几个小时我会处于 AFK 状态。 我试过了,但它根本不起作用。我仍然遇到同样的错误。看来基本上任何与 opencv (cv::) 相关的东西都有错误。echo $(pkg-config --libs opencv)
的输出是什么?
Mh 从输出中可以清楚地看出您的安装有问题。它应该只打印出-lopencv...
的序列,其中...
是特定opencv 元素的名称。请仔细描述您为安装 opencv 所做的一切。【参考方案2】:
已修复:使用本指南重新安装:
https://medium.com/@debugvn/installing-opencv-3-3-0-on-ubuntu-16-04-lts-7db376f93961
仅使用 g++ $(pkg-config --cflags --libs opencv) letter_recog.cpp -o letter_recog
无法正常工作,因此我必须添加一些标志 (-lopencv_name_of_library)
我对 makefile 有点不熟悉。一旦我找到了用 Makefiles 用文件名替换变量的方法,我将在此处提供一个自定义 makefile(作为编辑)来编译/构建项目,但到目前为止,因为我使用的是一个名为 Geany的 IDE >,我正在使用 build 命令(对于所有项目,不管是哪个)
g++ $(pkg-config --cflags --libs opencv) %f -o %e -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_photo -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_ml -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_flann -lopencv_xobjdetect -lopencv_imgcodecs -lopencv_objdetect -lopencv_xphoto -lopencv_imgproc -lopencv_core
感谢大家的帮助。最有用的评论是建议我安装不正确的评论。希望我的发现对其他人有所帮助。 (相信我,这是地狱,在尝试了不同的安装指南后,尝试安装 nvidia 驱动程序并损坏了我的整个操作系统,所以我不得不卸载该操作系统,重新安装操作系统,然后重新开始(失去了所有我的文件正在处理中))
希望你们不必经历我遇到的麻烦。这是地狱,但我认为 opencv 非常值得。
【讨论】:
以上是关于谁用过python中的第三方库face recognition的主要内容,如果未能解决你的问题,请参考以下文章
jquery-easyui中的datetimebox 谁用过?怎么改变日期格式??
谁用过三菱 PLC, 简单运动模块 LD77MS16 的FB库,代理商给提供的是日语版的不能安装使用,怎么办
CPP 中的 OpenCV 库(特别是文件 letter_recog.cpp)