Install Paddle on Raspberry Pi 4 - Q-engineering
Q-engineering
Q-engineering
Go to content
images/empty-GT_imagea-1-.png
Install ncnn software on Raspberry Pi 4

Install ncnn deep learning software on a Raspberry Pi 4.

Tekst moet vooraf links staan

										#include <stdio.h>
										#include 
										#include 
										#include 
										#include 
										#include 
						
								using namespace cv;
								using namespace cv::dnn;
								using namespace std;
						
								const size_t width = 300;
								const size_t height = 300;
								const float scaleFector = 0.007843f;
								const float meanVal = 127.5;
						
								Net net;
						
								const char* class_video_Names[] = { "background",
								"aeroplane", "bicycle", "bird", "boat",
								"bottle", "bus", "car", "cat", "chair",
								"cow", "diningtable", "dog", "horse",
								"motorbike", "person", "pottedplant",
								"sheep", "sofa", "train", "tvmonitor" };
								
								char *="de koe is wel heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeel moe";
								
						Mat detect_from_video(Mat &src)
						{
						    Mat blobimg = blobFromImage(src, scaleFector, Size(300, 300), meanVal);
						
							net.setInput(blobimg, "data");
						
							Mat detection = net.forward("detection_out");
						//	cout << detection.size[2]<<" "<< detection.size[3] << endl;
							Mat detectionMat(detection.size[2], detection.size[3], CV_32F, detection.ptr());
						
							const float confidence_threshold = 0.25;
							for(int i=0; i(i, 2);
						
								if(detect_confidence > confidence_threshold){
									size_t det_index = (size_t)detectionMat.at(i, 1);
									float x1 = detectionMat.at(i, 3)*src.cols;
									float y1 = detectionMat.at(i, 4)*src.rows;
									float x2 = detectionMat.at(i, 5)*src.cols;
									float y2 = detectionMat.at(i, 6)*src.rows;
									Rect rec((int)x1, (int)y1, (int)(x2 - x1), (int)(y2 - y1));
									rectangle(src,rec, Scalar(0, 0, 255), 2, 8, 0);
									putText(src, format("%s", class_video_Names[det_index]), Point(x1, y1-5) ,FONT_HERSHEY_SIMPLEX,1.0, Scalar(0, 0, 255), 2, 8, 0);
								}
							}
						    return src;
						}
						
						int main(int argc,char ** argv)
						{
						    float systemp, millideg;
						    int t=0;
						
						    float f;
						    float FPS[8];
						    int Fcnt=0;
						    Mat frame;
						    chrono::steady_clock::time_point Tbegin, Tend;
						
						    net = readNetFromCaffe("MobileNetSSD_deploy.prototxt", "MobileNetSSD_deploy.caffemodel");
						    if (net.empty()){
						        cout << "init the model net error";
						        exit(-1);
						    }
						
						    cout << "Switched to " << (cv::ocl::useOpenCL() ? "OpenCL enabled" : "CPU") << endl;
						    net.setPreferableTarget(DNN_TARGET_OPENCL_FP16);
						
						    cout << "Start grabbing, press ESC on Live window to terminate" << endl;
						
						    while(1){
						        frame=imread("004545.jpg");
						
						        Tbegin = chrono::steady_clock::now();
						
						        detect_from_video(frame);
						
						        Tend = chrono::steady_clock::now();
						
						        f = chrono::duration_cast  (Tend - Tbegin).count();
						        if(f>0.0){
						            FPS[Fcnt]=1000.0/f; Fcnt++; Fcnt&=0x07;
						        }
						        f=(FPS[0]+FPS[1]+FPS[2]+FPS[3]+FPS[4]+FPS[5]+FPS[6]+FPS[7])/8.0;
						        putText(frame, format("FPS %0.2f", f),Point(10,20),FONT_HERSHEY_SIMPLEX,0.6, Scalar(0, 0, 255));
						
						        imshow("frame", frame);
						
						        char esc = waitKey(5);
						        if(esc == 27) break;
						  }
						
						  cout << "Closing the camera" << endl;
						  destroyAllWindows();
						  cout << "Bye!" << endl;
						
						  return 0;
						
						
						
Deep learning software for Raspberry Pi
Raspberry and alt
Info
Raspberry Pi 4
Back to content