Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File path from a usb camera

Tags:

c++

vba

gdi+

wia

Hello I am using GDI+ to do some image processing. I am having it run from the command line with two arguments. The reason for this is the program is being called from VBA Excel 2007. A Open file dialog is run from VBA and gives the first argument.

The first arguement is the original image to be processed and the second is where to save the image. Everything works just fine when the two arguments come from a drive with a letter, i.e. C:.

It was not working with network folders, i.e. \server\folder. I overcame this by mounting the folder to a drive letter before trying to load the image.

I have a problem now when the incoming image is on a usb camera. The file path of the file on the camera ends up being COMPUTER\Canon\DCIM\image.jpg. Windows is not mounting the camera to a lettered drive so it is not working correctly for me.

Before trying to load the image I add and extra '\' so that they are all double \.

I am not sure at all how to get this to work and have looked all over. Thanks.

int main(int argc, char* argv[])
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR           gdiplusToken;

// INITIALIZE GDI+
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

wchar_t tin[200] = L"";
wchar_t in[200] = L"";
wchar_t out[200] = L"";
wchar_t tout[200] = L"";

NETRESOURCE nr;
DWORD dwRetVal;

nr.dwType = RESOURCETYPE_DISK;
nr.lpLocalName = "M:";
nr.lpRemoteName = "\\\\server\\folder";
nr.lpProvider = NULL;
// Map the mugshots folder
dwRetVal = WNetAddConnection2(&nr, NULL, NULL, CONNECT_TEMPORARY);

// Convert to a wchar_t* from command line argument
size_t origsize = strlen(argv[1]) + 1;
mbstowcs( tin, argv[1], origsize);

//Add an extra \ for directory
int j = 0;
for (int i = 0 ; i < int(origsize) ; i++)
{
    if(tin[i] == '\\')
    {
        in[j] = '\\';
        j++;
        in[j] = '\\';
        j++;
    }
    else
    {
        in[j] = tin[i];
        j++;
    }
}

// Convert to a wchar_t* from command line argument
origsize = strlen(argv[2]) + 1;
mbstowcs(tout, argv[2], origsize);
//Add an extra \ for directory

out[0] = 'M';
out[1] = ':';
out[2] = '\\';
out[3] = '\\';
j = 4;
for (int i = 0 ; i < int(origsize) ; i++)
{
    if(tout[i] == '\\')
    {
        out[j] = '\\';
        j++;
        out[j] = '\\';
        j++;
    }
    else
    {
        out[j] = tout[i];
        j++;
    }
}

Bitmap b(in);

Process image

CLSID pngClsid;
GetEncoderClsid(L"image/jpeg", &pngClsid);
image2->Save(out, &pngClsid, NULL);

return 0;
}
like image 257
BenB Avatar asked Jun 18 '11 07:06

BenB


People also ask

How do I view USB camera on Windows?

To open up your webcam or camera, select the Start button, then select All apps, and then select Camera in the list of apps. If you have multiple cameras, you can switch between them by selecting Change Camera at the top right once the Camera app is opened.

How do I use the USB camera on my Jetson Nano?

In the Jetson Camera Architecture, a V4L2 camera stream is available to an application in two different ways. The first way is to use the V4L2 interface directly using ioctl controls, or through a library that has a V4L2 backend. The second way is to use GStreamer which is a media processing framework.


1 Answers

Please take a look at the sample: GetImage Sample: Demonstrates the Windows Image Acquisition API:

The sample application has a single command on its File menu, named From scanner or camera. When a WIA device (or a device emulator) is attached, the menu item becomes enabled. When the user selects the menu command, the sample will sequentially display the WIA Device Selection dialog box, Image Selection dialog box, and Image Transfer dialog box. The device and image selection dialog boxes are the common dialog boxes supplied by the system, and the transfer dialog box is implemented in this sample. Finally, the sample will display the transferred image(s) in child window(s).

Hope this helps.

like image 63
Sergey Vyacheslavovich Brunov Avatar answered Oct 13 '22 18:10

Sergey Vyacheslavovich Brunov