Skip to content

Commit

Permalink
send fovx and fovy
Browse files Browse the repository at this point in the history
  • Loading branch information
undef committed Feb 13, 2018
1 parent e975f7e commit cb8c697
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion client-sample/client-sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

int main(int argc, char** argv){

OpenNI2NetClient client;
OpenNI2NetClient client(3346);

cv::namedWindow("win", cv::WINDOW_AUTOSIZE);

Expand Down
4 changes: 2 additions & 2 deletions client/openni2-net-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ void OpenNI2NetClient::start() {
cloud->points.resize(cloud->height * cloud->width);


float fx = header.fov / float(OpenNI2FloatConversion); // Horizontal focal length
float fy = fx; // Vertcal focal length
float fx = header.fovx / float(OpenNI2FloatConversion); // Horizontal focal length
float fy = header.fovy / float(OpenNI2FloatConversion); // Vertcal focal length
float cx = ((float)cloud->width - 1.f) / 2.f; // Center x
float cy = ((float)cloud->height - 1.f) / 2.f; // Center y

Expand Down
3 changes: 2 additions & 1 deletion common/openni2-net-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct OpenNI2NetHeader{
OpenNI2SizeType size;
OpenNI2SizeType width;
OpenNI2SizeType height;
OpenNI2SizeType fov;
OpenNI2SizeType fovx;
OpenNI2SizeType fovy;
uint8_t jpeg;
};
17 changes: 13 additions & 4 deletions server/grabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ void Grabber::start() {
void Grabber::onNewFrame(openni::VideoStream &in) {
if(!callback) return;

int frameWidth = stream.getVideoMode().getResolutionX();
float frameWidth = stream.getVideoMode().getResolutionX();
float frameHeight = stream.getVideoMode().getResolutionY();
float hFov = stream.getHorizontalFieldOfView();
fov = boost::numeric_cast<OpenNI2SizeType>(frameWidth / (2.0f * std::tan(hFov / 2.0f)) * OpenNI2FloatConversion);
float wFov = stream.getVerticalFieldOfView();
fovx = boost::numeric_cast<OpenNI2SizeType>(frameWidth / (2.0f * std::tan(wFov / 2.0f)) * OpenNI2FloatConversion);
fovy = boost::numeric_cast<OpenNI2SizeType>(frameHeight / (2.0f * std::tan(hFov / 2.0f)) * OpenNI2FloatConversion);

openni::VideoFrameRef ref;
in.readFrame(&ref);
Expand All @@ -74,6 +77,8 @@ void Grabber::onNewFrame(openni::VideoStream &in) {
const int height = ref.getHeight();
auto pixels = static_cast<const openni::DepthPixel*>(ref.getData());

openni::CoordinateConverter::convertDepthToWorld()

callback(pixels, width, height);
}

Expand All @@ -85,6 +90,10 @@ int Grabber::getHeight() {
return stream.getVideoMode().getResolutionY();
}

OpenNI2SizeType Grabber::getFov() {
return fov;
OpenNI2SizeType Grabber::getFovX() {
return fovx;
}

OpenNI2SizeType Grabber::getFovY() {
return fovy;
}
5 changes: 3 additions & 2 deletions server/grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Grabber: public openni::VideoStream::NewFrameListener{

Callback callback;

OpenNI2SizeType fov;
OpenNI2SizeType fovy, fovx;

public:
Grabber();
Expand All @@ -28,7 +28,8 @@ class Grabber: public openni::VideoStream::NewFrameListener{
void setCallback(const Callback& c);
void start();

OpenNI2SizeType getFov();
OpenNI2SizeType getFovX();
OpenNI2SizeType getFovY();

private:
void onNewFrame(openni::VideoStream& in) override;
Expand Down
11 changes: 7 additions & 4 deletions server/sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Sender::Sender(const std::string &h, unsigned p) :
sizeSent,
boost::numeric_cast<OpenNI2SizeType>(matToSend.cols),
boost::numeric_cast<OpenNI2SizeType>(matToSend.rows),
fov,
fovx,
fovy,
0
};
socket.send(boost::asio::buffer(&header, sizeof(OpenNI2NetHeader)));
Expand All @@ -74,7 +75,8 @@ Sender::Sender(const std::string &h, unsigned p) :
sizeSent,
boost::numeric_cast<OpenNI2SizeType>(matToSend.cols),
boost::numeric_cast<OpenNI2SizeType>(matToSend.rows),
fov,
fovx,
fovy,
1
};
socket.send(boost::asio::buffer(&header, sizeof(OpenNI2NetHeader)));
Expand Down Expand Up @@ -143,8 +145,9 @@ void Sender::setCompressionQuality(int quality) {
compressionQuality = quality;
}

void Sender::setFov(OpenNI2SizeType f) {
void Sender::setFov(OpenNI2SizeType fx, OpenNI2SizeType fy) {
std::lock_guard<std::mutex> lk(cvMtx);
fov = f;
fovx = fx;
fovy = fy;
}

4 changes: 2 additions & 2 deletions server/sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Sender {
std::atomic_bool bUseCompression;
std::atomic_int compressionQuality;

OpenNI2SizeType fov;
OpenNI2SizeType fovx, fovy;

std::string host;
unsigned port;
Expand All @@ -44,5 +44,5 @@ class Sender {
bool isConnected();
void setCompressed(bool state=true);
void setCompressionQuality(int quality);
void setFov(OpenNI2SizeType fov);
void setFov(OpenNI2SizeType fx, OpenNI2SizeType fy);
};
2 changes: 1 addition & 1 deletion server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main(int argc, char** argv) {

bNewMat = true;

sender.setFov(grabber.getFov());
sender.setFov(grabber.getFovX());
sender.send(depthMat);
});

Expand Down

0 comments on commit cb8c697

Please sign in to comment.