ÉèÖÃ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ϵͳÒÔÖ§³ÖͼÏñÊÕÂÞºÍÊÓƵ´¦Öóͷ£¿ª·¢µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡