Hello, I am making project in which I used ESP32-CAM to create a Wi-Fi network that I connect to with my laptop. So far I have been using method of downloading images using libcurl inside my application on laptop.
And it works but I have found that OpenCV function "cv::VideoCapture" can stream from URLs so I have tried passing URL but it didn't work.
Basically I have been using "192.168.4.1/capture" as an URL but I would like to try "192.168.4.1:81/stream" if it wouldn't make my video on laptop run more "smoothly".
Code inside ESP32-CAM is from this nice tutorial:
Code inside my C++ app is something like this:
cv::Mat curlImg(const char* img_url, int timeout = 10) // Retrieves the image as cv::Mat data type
{
std::vector<uchar> stream;
CURL* curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, img_url); //the img url
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); // pass the writefunction
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream); // pass the stream ptr to the writefunction
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); // timeout if curl_easy hangs,
CURLcode res = curl_easy_perform(curl); // start curl
curl_easy_cleanup(curl); // cleanup
return cv::imdecode(stream, -1); // 'keep-as-is'
}
int main()
{
//cv::VideoCapture cam("http://192.168.4.1:81/stream"); I wanted to use this, but my program would just freeze
while (loop)
{
start = clock();
cv::Mat frame;
frame = curlImg("http://192.168.4.1/capture");
//bool b = cam.read(frame);
cv::imshow("Window", frame);
int key = cv::waitKey(1);
if (key == 27)
break;
endTime = clock();
int deltaTime = difftime(endTime, start);
std::cout << deltaTime << "\n";
}
return 0;
}
Thanks in advance for any help.