2016-09-07 1 views
0

나는 웹캠, arduino, 나무 딸기 및 IR 근접 센서를 사용해야하는 프로젝트에서 일하고 있습니다. 나는 google의 도움으로 모든 것을하기 위해 도착했다. 그러나 나는 정말로 큰 문제가 있다고 생각한다. 처리시 OpenCV 라이브러리를 사용하고 있으며 웹캠으로 얻을 수있는 윤곽선이 스케치의 중심에 있도록하고 싶습니다. 그러나 비디오를 옮기기 위해 도착한 모든 사람이 컨투어가 아니라 내 코드입니다. 나는 당신이 나를 :)가공에서 "findcontour"opencv가있는 등고선 위치

도움이 될 바랍니다 모든 최고의

알렉산더 당신이 사용할 수있는 방법은 캔버스의 원점을 이동 translate() 함수를 호출하는 것입니다

//////////////////////////////////////////// 
////////////////////////////////// LIBRARIES 
//////////////////////////////////////////// 

import processing.serial.*; 
import gab.opencv.*; 
import processing.video.*; 




///////////////////////////////////////////////// 
////////////////////////////////// INITIALIZATION 
///////////////////////////////////////////////// 

Movie mymovie; 
Capture video; 
OpenCV opencv; 
Contour contour; 




//////////////////////////////////////////// 
////////////////////////////////// VARIABLES 
//////////////////////////////////////////// 

int lf = 10; // Linefeed in ASCII 
String myString = null; 
Serial myPort; // The serial port 
int sensorValue = 0; 
int x = 300; 




///////////////////////////////////////////// 
////////////////////////////////// VOID SETUP 
///////////////////////////////////////////// 

void setup() { 
    size(1280, 1024); 
    // List all the available serial ports 
    printArray(Serial.list()); 
    // Open the port you are using at the rate you want: 
    myPort = new Serial(this, Serial.list()[1], 9600); 
    myPort.clear(); 
    // Throw out the first reading, in case we started reading 
    // in the middle of a string from the sender. 
    myString = myPort.readStringUntil(lf); 
    myString = null; 
    opencv = new OpenCV(this, 720, 480); 
    video = new Capture(this, 720, 480); 
    mymovie = new Movie(this, "visage.mov"); 
    opencv.startBackgroundSubtraction(5, 3, 0.5); 
    mymovie.loop(); 
} 




//////////////////////////////////////////// 
////////////////////////////////// VOID DRAW 
//////////////////////////////////////////// 

void draw() { 
    image(mymovie, 0, 0); 
    image(video, 20, 20); 
    //tint(150, 20); 
    noFill(); 
    stroke(255, 0, 0); 
    strokeWeight(1); 



    // check if there is something new on the serial port 
    while (myPort.available() > 0) { 
    // store the data in myString 
    myString = myPort.readStringUntil(lf); 
    // check if we really have something 
    if (myString != null) { 
     myString = myString.trim(); // let's remove whitespace characters 
     // if we have at least one character... 
     if (myString.length() > 0) { 
     println(myString); // print out the data we just received 
     // if we received a number (e.g. 123) store it in sensorValue, we sill use this to change the background color. 
     try { 
      sensorValue = Integer.parseInt(myString); 
     } 
     catch(Exception e) { 
     } 
     } 
    } 
    } 
    if (x < sensorValue) { 
    video.start(); 
    opencv.loadImage(video); 
    } 

    if (x > sensorValue) { 
    image(mymovie, 0, 0); 
    } 

    opencv.updateBackground(); 
    opencv.dilate(); 
    opencv.erode(); 

    for (Contour contour : opencv.findContours()) { 
    contour.draw(); 
    } 

} 




////////////////////////////////////////////// 
////////////////////////////////// VOID CUSTOM 
////////////////////////////////////////////// 

void captureEvent(Capture video) { 
    video.read(); // affiche l'image de la webcam 
} 

void movieEvent(Movie myMovie) { 
    myMovie.read(); 
} 
+0

crossposts 사이를 연결하십시오 : https://forum.processing.org/two/discussion/18103/how-to-change-position-of-contour-opencv –

답변

0

하나 contour.draw()에 전화하기 전에 이런 식으로 뭔가가 :

translate(moveX, moveY); 

for (Contour contour : opencv.findContours()) { 
    contour.draw(); 
} 

당신이 moveXmoveY에 사용하는 것은 정확하게 당신이 뭘 하려는지에 전적으로 의존한다. 동영상을 그리기 위해 사용하는 위치를 사용하거나 (윤곽선을 동영상 상단에 표시하려는 경우) width/2height/2을 사용할 수 있습니다. 윤곽을 실제로 가운데 정렬하려면 약간 빼기 만하면됩니다.

자세한 내용은 the reference에서 찾을 수 있습니다. 다양한 값으로 재생하고 붙어 있다면 MCVE을 게시하십시오. 행운을 빕니다.

+0

안녕하세요 Kevin, 정말 고맙습니다. "translate(); " 너비/x와 높이/x를 사용했다. 다시 한 번 감사드립니다. :) – Alexandre