forked from imatest/Operator-Console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImatestLibAcq.cpp
157 lines (124 loc) · 4.01 KB
/
ImatestLibAcq.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/****************************************************************************
* Operator Console - an extensible user interface for the Imatest IT *
* library *
* Copyright (C) 2013 Imatest LLC. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************/
#include "stdafx.h"
#include "imatest_library.h"
#include "ImatestLibAcq.h"
#include "ThreadControl.h"
#include "imatest_acquisition.h"
#include "ImatestSourceIDs.h"
#include <iostream>
using namespace std;
#define IMAQ_WEBCAM_SOURCE_ID 128
#define EPIPHAN_SOURCE_ID 6
#define EPIPHAN_DEVICE_ID 0.0
// This is the source id for the first Image acquisition toolkit device
// const unsigned short isource_id = IMAQ_WEBCAM_SOURCE_ID;
const unsigned short isource_id = EPIPHAN_SOURCE_ID;
ImatestLibAcq::ImatestLibAcq(void)
{
m_width = 0;
m_height = 0;
m_numBytes = 0;
m_numPixels = 0;
m_buf = NULL;
m_source_ID = 0;
m_device_ID = 0;
m_ini_file = "";
}
ImatestLibAcq::~ImatestLibAcq(void)
{
}
bool ImatestLibAcq::Open()
{
//struct SimpleCapParams params;
bool success = false;
m_inited = true;
if (m_width == 0 || m_height == 0) // these get set in Init()
{
m_logMsg = "Unable to Open camera: width and height are not set.";
}
else
{
}
return m_inited;
}
bool ImatestLibAcq::Close()
{
if (m_inited)
{
//deinitCapture(m_cameraIndex);
}
return true;
}
bool ImatestLibAcq::CaptureFrame()
{
// This required parameter will hold return data.
mwArray out;
//mwArray nover;
// Load our file in
//raw_pixels_char = load_raw_file(BLEMISH_RAW_FILE, &pixel_count);
mwArray im_orig, vstr;
mwArray source_id((mxDouble)m_source_ID);
mwArray toRGBrows = mwArray(1,1,mxDOUBLE_CLASS);
toRGBrows=1.0;// by being TRUE we call for the image to be in column major format
mwArray deviceID((mxDouble)m_device_ID);// select which source we are using
mwArray ini_file(m_ini_file.c_str()); // the Omnivision part of acquire_image needs to read from
// the correct imatest.ini file
//const double varArgIn[] = {1.0, 1.0};
mwArray vararginParam = mwArray(1,2,mxCELL_CLASS);
vararginParam.Get(1,1).Set(toRGBrows);
if ( m_source_ID == SOURCE_Omnivision)
{
vararginParam.Get(1,2).Set(ini_file); // Path to INI file
}
else
{
vararginParam.Get(1,2).Set(deviceID); // 16bit RAW data
}
try
{
acquire_image(2, im_orig, vstr, source_id, vararginParam);
}
catch (mwException& e)
{
cout << "Run Error!" << endl;
cerr << e.what() << endl;
e.print_stack_trace();
}
//im_orig.GetData((mxUint64*)m_buf,(mwSize)im_orig.ElementSize());
mwSize dataSize = im_orig.NumberOfElements();
if (dataSize*im_orig.ElementSize() != m_numBytes && m_buf != NULL)
{
m_numBytes = dataSize*im_orig.ElementSize();
delete[] m_buf;
m_buf = new byte[m_numBytes];
if (NULL == m_buf)
{
m_logMsg.Format("%s: Unable to allocate image buffer (%u bytes)", __FUNCTION__, m_numPixels);
}
}
im_orig.GetData((mxUint8*)m_buf, dataSize);
//m_buf = (char*)mxGetPr(im_orig);
//doCapture(m_cameraIndex);
//while (!isCaptureDone(m_cameraIndex)) // captures into m_buf
//{
// Sleep(1);
//}
return true;
}