mirror of https://github.com/ArduPilot/ardupilot
AP_HAL_Linux: add yuyv_to_grey() and crop_8bpp() to VideoIn
Most cameras do not support NV12 or GREY formats, we are adding in this commit a conversion from YUYV format, that seems pretty common in cameras, to GREY format (since we do not use Cb and Cr data on OpticalFlow). Also we are adding a software crop for 8bpp images, such as GREY format. For the same reason, most cameras do not have support for overlaying (crop, resize and so on). These functions are being added in order to be used in the next commits, where we will add support for OpticalFlow on MinnowBoardMax.
This commit is contained in:
parent
27f909319e
commit
8aded390e7
|
@ -249,6 +249,32 @@ void VideoIn::prepare_capture()
|
|||
}
|
||||
}
|
||||
|
||||
void VideoIn::crop_8bpp(uint8_t *buffer, uint8_t *new_buffer,
|
||||
uint32_t width, uint32_t left, uint32_t crop_width,
|
||||
uint32_t top, uint32_t crop_height)
|
||||
{
|
||||
for (uint32_t j = top; j < top + crop_height; j++) {
|
||||
for (uint32_t i = left; i < left + crop_width; i++) {
|
||||
new_buffer[(i - left) + (j - top) * crop_width] =
|
||||
buffer[i + j * width];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VideoIn::yuyv_to_grey(uint8_t *buffer, uint32_t buffer_size,
|
||||
uint8_t *new_buffer)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t new_buffer_position = 0;
|
||||
|
||||
for (i = 0; i < buffer_size; i++) {
|
||||
if (i % 2 == 0) {
|
||||
new_buffer[new_buffer_position] = buffer[i];
|
||||
new_buffer_position++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t VideoIn::_timeval_to_us(struct timeval& tv)
|
||||
{
|
||||
return (1.0e6 * tv.tv_sec + tv.tv_usec);
|
||||
|
|
|
@ -51,6 +51,14 @@ public:
|
|||
uint32_t width, uint32_t height);
|
||||
void prepare_capture();
|
||||
|
||||
static void crop_8bpp(uint8_t *buffer, uint8_t *new_buffer,
|
||||
uint32_t width, uint32_t left,
|
||||
uint32_t crop_width, uint32_t top,
|
||||
uint32_t crop_height);
|
||||
|
||||
static void yuyv_to_grey(uint8_t *buffer, uint32_t buffer_size,
|
||||
uint8_t *new_buffer);
|
||||
|
||||
private:
|
||||
void _queue_buffer(int index);
|
||||
bool _set_streaming(bool enable);
|
||||
|
|
Loading…
Reference in New Issue