4

LEDの点滅でビデオ(mp4)を分析したい。背景は通常灰色ですが、LED の色は異なる場合があります。LED はビデオに十分近いので、LED ライトはフレームの最大の部分です。Color-Thief を見つけましたが、これは画像用であり、ビデオ用ではありません。点滅の頻度も異なる場合があるため、ビデオの各フレームで主要な色を確認する必要があります。

誰かが何かアイデアを持っているなら、私は大いに助けていただければ幸いです。お時間をいただきありがとうございます。

編集: ビデオの 2 つのスクリーンショット (最初の赤い LED がオフ、2 番目の赤い LED がオン) (2 つのスクリーンショット リンクのカラー泥棒のリンクを削除する必要がありました)

http://imgur.com/AXwSLl8

http://imgur.com/a/2zFOq#0

これは、ビデオの再生が開始されたときに呼び出され、ビデオを分析する必要がある関数です。私は平均的な色でそれをやろうとしましたが、それは通常ある種の灰色/茶色であるため役に立ちません.

function processFrame(e) {  

    var video = document.getElementById("video");

    if (video.ended){
        //dauer();
        console.log("Ende");
        //alert("Ende");
    }

    if (video.paused || video.ended) {
        return;
    }

    var bufferCanvas = document.getElementById("buffer");
    var displayCanvas = document.getElementById("display");
    var buffer = bufferCanvas.getContext("2d");
    var display = displayCanvas.getContext("2d");

    buffer.drawImage(video, 0,0, bufferCanvas.width, displayCanvas.height);

    var frame = buffer.getImageData(sx, sy, sw, sh);
    var length = frame.data.length / 4;

    for (var i = 0; i < length; i++) {
        var r = frame.data[i * 4 + 0];
        var g = frame.data[i * 4 + 1];
        var b = frame.data[i * 4 + 2];
        average= average +((r+g+b)/3)       
    }   

    averagecolor[i]=average

    display.putImageData(frame, 0, 0);

    setTimeout(processFrame, 0);
}
4

1 に答える 1

2

It's a bit broad what you're asking as you need to do this in several steps - but it's fully possible to do. To shorten down I'll just present the steps you need to take in order to be able to analyze the LEDs.

You can do this fully automatic or semi-automatic be predefining the areas in the video frame.

The steps for automatic detection is as follows and is used once per session in case camera is moved or zoom is changed. Lighting condition can affect the detection as well but here I will assume the lighting conditions are the same and as in the images you are showing. It's also specific for these images and may not work if you change setup of the routers/camera.

Initial step to auto-detect areas:

  • Scan horizontal lines half way and start registering regions when all RGB values = 255 (that's the white center of the leds). Set a flag that you are in a region and count number of pixels when you start to register based on a threshold (for example 7-10 pixels that needs to be white in a row). This is to eliminate single pixels that way be white.
  • When you cannot find any white pixels on a line (based on threshold) end region and prepare for new registration.
  • When at bottom of first half (i would set a max height shorted than actual height), start over scanning from middle to the right edge.

After this you should have six regions registered (use a "calibration" frame where all LEDs are lit - this can be ran manually before running live).

For next step which will be the one running constantly you will use these regions as anchor regions and to sample points only on one side and only a few pixels in height.

  • Use the region as anchor and define a sample region based on that with an offset x + width of region + 2 pixels as start X (this is just suggestion for an initial offset - you may have to fine-tune this). Offset Y + 10 and set width and height to 10 pixels. This should give you a sample region of 100 points right next to the led.
  • Run statistics on this small region by using getImageData. You need to check all three components as you need to filter away light-grey. Find a threshold (for instance if r > 230 && b < 200 && g < 200 just to take some values) when kicks in you accumulate your red value (and another for green). This process require a calibration phase to find that threshold value you need to use. Run some tests. If camera changes f-stop you will probably need to re-calibrate.
  • Accumulate the green and red values to different variables. You do not not need to average them but you will need to find a threshold value for the total sum where you know the led is lit for the LED with that color (use the initial test frame from region detection for this as well). Add some tolerance to the values by comparing the regions when the LEDs are off.

This will give you in total only 600 points to scan maybe less if you can fine-tune it.

For the manual method you skip the region setting as described in first step but use a frame and set the regions manually by measuring pixels of the white top. If you change the camera position you will need to do it over.

As you understand there is a bit code that need to be written for this and there are many factors that will affect the final code making it very specific for this usage. And I believe it's in part outside the scope for SO but I hope this gives you some leads to get you going.

于 2013-08-09T03:33:23.210 に答える