2011-08-20 4 views
1

Je voudrais définir Région d'intérêt dans la fenêtre avec l'image capturée à partir de la caméra .. Comment faire cela? J'utilise C# avec OpenCVSharp et Visual C#.OpenCV définir ROI dans la fenêtre de streaming de caméra

Quelque chose comme ça:

using (CvCapture cap = CvCapture.FromCamera(0)) // device type + camera index 
using (CvWindow v = new CvWindow("Live Stream")) 
while (CvWindow.WaitKey(10) < 0) 
      { 
       using (IplImage src = cap.QueryFrame()) 
       v.Image = src; 
       // Then set ROI and send it to picturebox 
       pictureBox.Image = BitmapConverter.ToBitmap(ROI); 
      } 

Répondre

1

Je ne sais pas C#, mais voici comment je le ferais en C++ (avec OpenCV 2). J'espère que la traduction est facile. L'instruction Mat roiRect = frame(Rect(200,200,100,100)); crée un en-tête qui partage des données avec frame mais uniquement dans la région d'intérêt.

using namespace cv; 

int main(int argc, const char * argv[]) { 

    VideoCapture cap; 
    if(argc > 1) 
     cap.open(string(argv[1])); 
    else 
     cap.open(0); 
    Mat frame; 
    namedWindow("video", 1); 
    for(;;) { 
     cap >> frame; 
     if(!frame.data) 
      break; 

     //Create the region of interest 
     Mat roiRect = frame(Rect(200,200,100,100)); 
     //Do something with the region of interest 
     roiRect *= 0.4; 

     imshow("video", frame); 
     if(waitKey(30) >= 0) 
      break; 
    } 

    return 0; 
} 
0

Je voudrais créer un rectangle sur le haut de l'image, à la suite this link pourrait aider.

Utilisez le rectangle créé pour recadrer la zone sélectionnée:

Rectangle cropArea new Rectangle(0, 0, 10, 10); 
    Bitmap bmpImage = new Bitmap(img); 
    Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat); 
Questions connexes