ÉèÖÃLinuxϵͳÒÔÖ§³ÖͼÏñÊÕÂÞºÍÊÓƵ´¦Àí¿ª·¢
ÉèÖÃlinuxϵͳÒÔÖ§³ÖͼÏñÊÕÂÞºÍÊÓƵ´¦Àí¿ª·¢
¼ò½é£º
ÏÖ´úÅÌËã»úÊÓ¾õÁìÓòµÄ¿ìËÙÉú³¤Ê¹µÃͼÏñÊÕÂÞºÍÊÓƵ´¦Àí³ÉΪÁËÑо¿ºÍ¿ª·¢Öв»¿É»òȱµÄÒ»²¿·Ö¡£¶øÒªÔÚLinuxϵͳÉϾÙÐÐÓÐÓõÄͼÏñÊÕÂÞºÍÊÓƵ´¦Àí¿ª·¢£¬ÐèÒª¾ÙÐÐһЩÉèÖᣱ¾ÎĽ«ÏÈÈÝÔõÑùÔÚLinuxϵͳÉÏÉèÖÃÇéÐÎÒÔÖ§³ÖͼÏñÊÕÂÞºÍÊÓƵ´¦ÀíµÄ¿ª·¢£¬²¢ÇÒÌṩһЩ´úÂëʾÀý¡£
Ò»¡¢×°ÖÃÏà»úÇý¶¯
Òª¾ÙÐÐͼÏñÊÕÂÞ£¬ÎÒÃÇÊ×ÏÈÐèҪװÖÃÏà»úµÄÇý¶¯³ÌÐò¡£´ó´ó¶¼Ïà»ú×°±¸¶¼»áË渽Çý¶¯³ÌÐò£¬ÎÒÃÇÖ»ÐèҪƾ֤Çý¶¯³ÌÐòµÄ×°ÖÃÖ¸ÄϾÙÐÐ×°Öü´¿É¡£ÈôÊÇÄúʹÓõÄÊÇUSBÏà»ú£¬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÉó²éÏà»úÊÇ·ñ±»Ê¶±ð£º
lsusb
µÇ¼ºó¸´ÖÆ
ÈôÊÇÏà»úÀֳɱ»Ê¶±ð£¬ÄÇô˵Ã÷Çý¶¯ÒѾװÖÃÀֳɡ£
¶þ¡¢×°ÖÃOpenCV¿â
OpenCVÊÇÒ»¸öÇ¿Ê¢µÄÅÌËã»úÊÓ¾õ¿â£¬ÌṩÁ˸»ºñµÄͼÏñ´¦ÀíºÍÊÓƵ´¦Àí¹¦Ð§¡£ÔÚLinuxϵͳÉÏ£¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî×°ÖÃOpenCV¿â£º
sudo apt-get install libopencv-dev
µÇ¼ºó¸´ÖÆ
×°ÖÃÍê³Éºó£¬ÎÒÃǾͿÉÒÔÔÚ´úÂëÖÐʹÓÃOpenCV¿â¾ÙÐÐͼÏñºÍÊÓƵ´¦ÀíÁË¡£
Èý¡¢Ò»Ð©Í¼ÏñÊÕÂÞºÍÊÓƵ´¦ÀíµÄ´úÂëʾÀý
ÒÔÏÂÊÇһЩ»ù±¾µÄͼÏñÊÕÂÞºÍÊÓƵ´¦ÀíµÄ´úÂëʾÀý£¬¿É¹©²Î¿¼ºÍʹÓá£
ͼÏñÊÕÂÞʾÀý
#include <opencv2/opencv.hpp> int main() { cv::VideoCapture cap(0); // ·¿ªÏà»ú×°±¸£¬0ÌåÏÖĬÈÏÏà»ú if (!cap.isOpened()) { // ÅжÏÏà»úÊÇ·ñÀֳɷ¿ª std::cout << "Ïà»úÎÞ·¨·¿ª£¡" << std::endl; return -1; } cv::Mat frame; while (true) { cap >> frame; // ´ÓÏà»úÖжÁȡһ֡ͼÏñ cv::imshow("Camera", frame); // ÏÔʾͼÏñ if (cv::waitKey(1) == 'q') { // °´Ï 'q' ¼üÍ˳öÑ»· break; } } return 0; }
µÇ¼ºó¸´ÖÆ
ÒÔÉÏ´úÂëͨ¹ý·¿ªÏà»ú×°±¸²¢Ò»Ö±¶ÁȡͼÏñÖ¡£¬ÊµÏÖÁËʵʱԤÀÀÏà»úͼÏñµÄ¹¦Ð§¡£
ͼÏñ´¦ÀíʾÀý
#include <opencv2/opencv.hpp> int main() { cv::Mat image = cv::imread("image.jpg"); // ¶ÁȡͼÏñÎļþ if (image.empty()) { // ÅжÏͼÏñÊÇ·ñÀֳɶÁÈ¡ std::cout << "ͼÏñÎÞ·¨¼ÓÔØ£¡" << std::endl; return -1; } cv::cvtColor(image, image, cv::COLOR_BGR2GRAY); // ½«²ÊɫͼÏñת»»Îª»Ò¶ÈͼÏñ cv::imshow("Gray Image", image); // ÏÔʾ´¦ÀíºóµÄͼÏñ cv::waitKey(0); return 0; }
µÇ¼ºó¸´ÖÆ
ÒÔÉÏ´úÂëͨ¹ý¶ÁȡͼÏñÎļþ£¬²¢½«Æäת»»Îª»Ò¶ÈͼÏñ£¬ÊµÏÖÁ˼òÆÓµÄͼÏñ´¦Àí¹¦Ð§¡£
ÊÓƵ´¦ÀíʾÀý
#include <opencv2/opencv.hpp> int main() { cv::VideoCapture cap(0); // ·¿ªÏà»ú×°±¸£¬0ÌåÏÖĬÈÏÏà»ú if (!cap.isOpened()) { // ÅжÏÏà»úÊÇ·ñÀֳɷ¿ª std::cout << "Ïà»úÎÞ·¨·¿ª£¡" << std::endl; return -1; } cv::Mat frame; while (true) { cap >> frame; // ´ÓÏà»úÖжÁȡһ֡ͼÏñ cv::cvtColor(frame, frame, cv::COLOR_BGR2GRAY); // ½«²ÊɫͼÏñת»»Îª»Ò¶ÈͼÏñ cv::imshow("Processed Image", frame); // ÏÔʾ´¦ÀíºóµÄͼÏñ if (cv::waitKey(1) == 'q') { // °´Ï 'q' ¼üÍ˳öÑ»· break; } } return 0; }
µÇ¼ºó¸´ÖÆ
ÒÔÉÏ´úÂëͨ¹ý¶ÁÈ¡Ïà»úͼÏñ£¬²¢½«Æäת»»Îª»Ò¶ÈͼÏñ£¬ÊµÏÖÁËʵʱԤÀÀÏà»úͼÏñ²¢¾ÙÐмòÆÓµÄÊÓƵ´¦Àí¡£
½áÓ
ͨ¹ý¶ÔLinuxϵͳ¾ÙÐÐÏà»úÇý¶¯µÄ×°ÖúÍOpenCV¿âµÄÉèÖã¬ÎÒÃÇ¿ÉÒÔÇáËɵؾÙÐÐͼÏñÊÕÂÞºÍÊÓƵ´¦ÀíµÄ¿ª·¢¡£Ê¹ÓÃÉÏÊöµÄ´úÂëʾÀý£¬Äú¿ÉÒÔ½øÒ»²½Ì½Ë÷ºÍ¿ª·¢¸ü¶àµÄͼÏñ´¦ÀíºÍÊÓƵ´¦Àí¹¦Ð§¡£×£ÄúÔÚͼÏñ´¦ÀíºÍÊÓƵ´¦ÀíµÄ¿ª·¢ÖÐÈ¡µÃÀֳɣ¡
ÒÔÉϾÍÊÇÉèÖÃLinuxϵͳÒÔÖ§³ÖͼÏñÊÕÂÞºÍÊÓƵ´¦Àí¿ª·¢µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡