Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "lsd.h"
- #include <opencv2/videoio.hpp>
- #include <opencv2/highgui.hpp>
- #include <opencv2/core.hpp>
- #include <opencv2/imgproc.hpp>
- #include <string>
- #include <iostream>
- #include <thread>
- #include <chrono>
- template<typename T>
- void initWebcam(cv::VideoCapture& videoCapture, T cameraNumber)
- {
- // Get access to the default camera.
- try { // Surround the OpenCV call by a try/catch block so we can give a useful error message!
- videoCapture.open(cameraNumber);
- }
- catch (cv::Exception& e) {
- std::cerr << "ERROR: Could not access the camera!" << std::endl;
- exit(1);
- }
- if (!videoCapture.isOpened()) {
- std::cerr << "ERROR: Could not access the camera!" << std::endl;
- exit(1);
- }
- std::cout << "Loaded camera " << cameraNumber << "." << std::endl;
- }
- int main() {
- cv::Mat frame;
- cv::VideoCapture cap;
- initWebcam(cap, "up1.mp4");
- std::this_thread::sleep_for(std::chrono::seconds(1));
- cap >> frame;
- while (!frame.empty()) {
- cv::Mat tmp, src_gray;
- frame.copyTo(src_gray);
- cv::cvtColor(frame, tmp, cv::COLOR_RGB2GRAY);
- tmp.convertTo(src_gray, CV_64FC1);
- int cols = src_gray.cols;
- int rows = src_gray.rows;
- image_double image = new_image_double(cols, rows);
- image->data = src_gray.ptr<double>(0);
- ntuple_list ntl = lsd(image);
- cv::Mat lsd = cv::Mat::zeros(rows, cols, CV_8UC1);
- cv::Point pt1, pt2;
- for (int j = 0; j != ntl->size; ++j) {
- pt1.x = ntl->values[0 + j * ntl->dim];
- pt1.y = ntl->values[1 + j * ntl->dim];
- pt2.x = ntl->values[2 + j * ntl->dim];
- pt2.y = ntl->values[3 + j * ntl->dim];
- cv::line(lsd, pt1, pt2, cv::Scalar(255), 1);
- }
- free_ntuple_list(ntl);
- cv::imshow("Result", frame);
- cv::namedWindow("lsd", cv::WINDOW_AUTOSIZE);
- cv::imshow("lsd", lsd);
- if (cv::waitKey(30) >= 0)
- break;
- cap >> frame;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement