C# i Matrix Vision

0

Witam ,
Czy ktoś oriętuje się w Matix Vision i obsłudze kamer analagowych. Potrzebuje dopisać do programu który obsługuje kamere CCD , funkcje żeby mógł wybierać obraz z jednej z dwóch podłączonych kamer do frame grabera (mv-gamma-g) a konkretnie zeby w jednym oknie był obraz z jednej kamery a w drugim drugiej.
Możliwe że to ta fukcja :
ConnectorFrameGrabber connector( pDev );
connector.videoChannel.write( newChannelNumber );

kod programu :

 using System;
using System.Threading;
using System.Collections;
using mvIMPACT_NET;
using mvIMPACT_NET.acquire;

namespace continuouscapture
{
class MyThread
{
public void repaint()
{
if (pWin != null) blnForceDraw = true;
}


public Palette palette = new Palette(256, 3);
public Image image;
public Image image1;

public void palGray()
{
gBase.presetPalette(palette, PalettePresetType.pptGrayLinear); pWin.colorPalette = palette; pWin.redraw();
}

public void saveToFile(String name)
{
Console.WriteLine("Rozpoczęto zapisywanie obrazu...");
gBase.saveImage(image, name, FileFormat.ffBmp, ref palette);
Console.WriteLine("Zakończono zapisywanie obrazu.");
}


public bool blnDraw = true;

private bool blnForceDraw = false;
private bool boTerminated = false;
private const int MAX_REQUESTS = 3;

private Device pDev;
public Window pWin;


public MyThread(Device dev,Window win)
{
this.pDev = dev;
this.pWin = win;
}

public void terminate()
{
boTerminated = true;
}

public void liveThread( )
{
//Console.WriteLine("Initialising the device. This might take some time..." );
try
{
pDev.open();

// To odpowiada za poprawne wyślwietlanie się obrazu
Settings settings = new Settings(ref pDev);
settings.imageDestination.pixelFormat.write(TImageDestinationPixelFormat.idpfMono8);
}
catch( ImpactAcquireException e )
{
// this e.g. might happen if the same device is already opened in another process...
Console.WriteLine("An error occurred while opening the device " + pDev.serial.read() +
"(error code: " + e.Message + "). Press any key to end the application..." );
Console.ReadLine();
Environment.Exit(0);
}

//Console.WriteLine( "Press [enter] key to end the application");

Statistics statistics = new Statistics(ref pDev);
FunctionInterface fi = new FunctionInterface(ref pDev);

fi.ensureRequests(MAX_REQUESTS);

for( int i=0; i<MAX_REQUESTS; i++ )
{
fi.imageRequestSingle();
}

Request pRequest;
Request pRequest1;

const int timeout_ms = 5000;
int requestNr = -1;
int requestNr1 = -1;

image = new Image();



while (!boTerminated)
{
// wait for results from the default capture queue

requestNr = fi.imageRequestWaitFor( timeout_ms );
requestNr1 = fi.imageRequestWaitFor(timeout_ms);
if (fi.isRequestNrValid(requestNr1)){
if (fi.isRequestNrValid(requestNr))
{
pRequest = fi.getRequest(requestNr);
pRequest1 = fi.getRequest(requestNr1);

if (fi.isRequestNrValid(requestNr1)){
if( fi.isRequestNrValid(requestNr) )
{
image = pRequest.getIMPACTImage(TImpactBufferFlag.ibfUseRequestMemory);
image1 = pRequest1.getIMPACTImage(TImpactBufferFlag.ibfUseRequestMemory);


//operacje na złapanym obrazie

if (null == pWin)
{
gBase.presetPalette(palette, PalettePresetType.pptGrayLinear);
pWin = new Window(image);
}
else if (blnDraw || blnForceDraw)
{
pWin.buffer = image;
}

if (blnDraw || blnForceDraw)
{
pWin.update();
}
blnForceDraw = false;

gBase.dispatchMessages();
}
}
else
{
Console.WriteLine( "Error: " + pRequest.result.result );
}
//for (int i = 0; i < MAX_REQUESTS; i++)
{
fi.imageRequestUnlock(requestNr);
fi.imageRequestSingle();
fi.imageRequestUnlock(requestNr1);
fi.imageRequestSingle();
}
}
}
else
{
Console.WriteLine("Acquisition error: {0}.", requestNr);
}
}
pDev.close();
}
}


class Class1
{

static Device getDeviceFromUserInput( ref DeviceManager devMgr ) /// funkcj frame grabera
{
uint devCnt = devMgr.deviceCount();
if(devCnt == 0 )
{
Console.WriteLine( "No MATRIX VISION device found!" );
return null;
}

// display every device detected
for( uint i=0; i<devCnt; i++ )
{
Device dev = devMgr.getDevice(i);
if( dev != null )
{
Console.WriteLine( "[{0}]: {1}({2}, family: {3})", i, dev.serial.read(), dev.product.read(), dev.family.read() );
}
}

// get user input
Console.Write("Please enter the number in front of the listed device followed by [ENTER] to open it: ");
uint devNr = System.Convert.ToByte(Console.ReadLine());
uint devNr1 = 0;
if( devNr >= devCnt )
{
Console.WriteLine( "Invalid selection!" );
return null;
}

Console.WriteLine( "Using device number {0}", devNr );
return devMgr.getDevice(devNr);
}

[MTAThread]
static void Main(string[] args)
{
try
{

DeviceManager devMgr = new DeviceManager();
Device dev = getDeviceFromUserInput( ref devMgr );

if( dev == null )
{
Console.WriteLine( "Unable to continue! Press any key to end the program." );
Console.Read();
Environment.Exit(0);
}

// start the execution of the 'live' thread.
MyThread liveThread = new MyThread( dev, null );
Thread threadControl = new Thread(new ThreadStart(liveThread.liveThread));
threadControl.Start();
Console.WriteLine("\nMenu:\n");
Console.WriteLine("Z - Zdjęcie");
Console.WriteLine("L - Liniowa paleta");
Console.WriteLine("S - Zachowaj obraz do pliku");

Console.WriteLine("\nQ - Wyjście\n");


string c;
while((c=gBase.getChar()).ToLower() != "q")
{
switch(c.ToLower())
{
case "z": liveThread.blnDraw = !liveThread.blnDraw; liveThread.repaint(); break;
case "l": liveThread.palGray(); liveThread.repaint(); break;
case "s":
Console.WriteLine("Podaj ścieżkę aa i nazwę pliku: \n");
String fileName = Console.ReadLine();
liveThread.saveToFile(fileName);
break;

}
}
liveThread.terminate();
threadControl.Join();
}

catch(ImpactException e)
{
Console.WriteLine(e.errorString);
}
}
}
}
//</matrixdoc></b></i>
0

wrzuć ten kod między tagi <‌code=csharp> a <‌/code>, z prawidłowymi wcięciami, bo w tej chwili nikomu nie będzie się chciało tego nawet czytać.

1

I umieść tylko najważniejsze części kodu, bo po np. otwieranie pliku?

0

najważniejsza część kodu jest to ////operacje na złapanym obrazie , chodzi o złapanie obrazu z obu kamer podłączonych do frame grabera

0

jakieś pomysły ??

0

Możliwe ze jeden watek nie może obsłużyć 2 kamer, jak dorobić drugi wątek dla drugiej kamery

1 użytkowników online, w tym zalogowanych: 0, gości: 1