完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
再Ubuntu的上交叉编译的OpenCV到嵌入式开发板交叉编译部分教程如下:
文件下载如下(caffemodel和网络模型): 再用opencv调用caffe模型进行人脸识别并截图。 这里cap(1)注意下。 #include #include #include #include #include #include using namespace cv; using namespace cv::dnn; using namespace std; const size_t inWidth = 300; const size_t inHeight = 300; const double inScaleFactor = 1.0; const Scalar meanVal(104.0, 177.0, 123.0); int main(int argc, char** argv) { float min_confidence = 0.5; String modelConfiguration = "deploy.prototxt"; String modelBinary = "res10_300x300_ssd_iter_140000.caffemodel"; //! [Initialize network] dnn::Net net = readNetFromCaffe(modelConfiguration, modelBinary); //! [Initialize network] if (net.empty()) { cerr << "Can't load network by using the following files: " << endl; cerr << "prototxt: " << modelConfiguration << endl; cerr << "caffemodel: " << modelBinary << endl; cerr << "Models are available here:" << endl; cerr << " cerr << "or here:" << endl; cerr << "https://github.com/opencv/opencv/tree/master/samples/dnn/face_detector" << endl; exit(-1); } VideoCapture cap(1); if (!cap.isOpened()) { cout << "Couldn't open camera : " << endl; return -1; } for (;;) { Mat frame; cap >> frame; // get a new frame from camera/video or read image if (frame.empty()) { waitKey(); break; } if (frame.channels() == 4) cvtColor(frame, frame, COLOR_BGRA2BGR); //! [Prepare blob] Mat inputBlob = blobFromImage(frame, inScaleFactor, Size(inWidth, inHeight), meanVal, false, false); //Convert Mat to batch of images //! [Prepare blob] //! [Set input blob] net.setInput(inputBlob, "data"); //set the network input //! [Set input blob] //! [Make forward pass] Mat detection = net.forward("detection_out"); //compute output //! [Make forward pass] vector double freq = getTickFrequency() / 1000; double time = net.getPerfProfile(layersTimings) / freq; Mat detectionMat(detection.size[2], detection.size[3], CV_32F, detection.ptr ostringstream ss; ss << "FPS: " << 1000 / time << " ; time: " << time << " ms"; putText(frame, ss.str(), Point(30, 80), 2, 2.5, Scalar(0, 0, 255)); float confidenceThreshold = min_confidence; for (int i = 0; i < detectionMat.rows; i++) { float confidence = detectionMat.at if (confidence > confidenceThreshold) { int xLeftBottom = static_cast int yLeftBottom = static_cast int xRightTop = static_cast int yRightTop = static_cast Rect object((int)xLeftBottom, (int)yLeftBottom, (int)(xRightTop - xLeftBottom), (int)(yRightTop - yLeftBottom)); rectangle(frame, object, Scalar(0, 255, 0),8); ss.str(""); ss << confidence; String conf(ss.str()); String label = "Face: " + conf; int baseLine = 0; Size labelSize = getTextSize(label, FONT_HERSHEY_SIMPLEX, 1, 4, &baseLine); rectangle(frame, Rect(Point(xLeftBottom, yLeftBottom - labelSize.height), Size(labelSize.width, labelSize.height + baseLine)), Scalar(255, 255, 255), CV_FILLED); putText(frame, label, Point(xLeftBottom, yLeftBottom), FONT_HERSHEY_SIMPLEX, 1, Scalar(0, 0, 0)); imwrite(label + "jt.jpg",frame); } } //imwrite("jt.jpg",frame); //if (waitKey(1) >= 0) break; } return 0; } arm-linux-gnueabihf-g++ -o camera camera.cpp `pkg-config --cflags --libs opencv` |
|
|
|
只有小组成员才能发言,加入小组>>
692 浏览 0 评论
1105 浏览 1 评论
2473 浏览 5 评论
2807 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2645 浏览 6 评论
使用eim外接fpga可是端口一点反应都没有有没有大哥指点一下啊
652浏览 9评论
649浏览 7评论
请教大神怎样去解决iMX6Q在linux3.0.35内核上做AP失败的问题呢
781浏览 6评论
628浏览 5评论
668浏览 5评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-21 20:02 , Processed in 0.935321 second(s), Total 79, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号