fastcv 教程1:yuv422转换rgb555颜色转换
本例程中首先你得有一个yuv422交叉 yuyv的数据 尺寸为640x480,然后转换为rgb565,可以通过yuvplayer进行查看。
#include "fastcv.h"
include "stdio.h"
include <stdio.h>
include <stdlib.h>
include <string.h>
include <assert.h>
include <sys/select.h>
include <fcntl.h> //low_level i/o
include <unistd.h>
include <errno.h>
include <malloc.h>
include <sys/stat.h>
include <sys/types.h>
include <sys/time.h>
include <sys/mman.h>
include <sys/ioctl.h>
include "mybmp.h"
ifdef __cplusplus
extern "C" {
endif / __cplusplus /
int yuvgetfromfrmae(unsigned char frame)
{
int index_y, index_uv, index_v,num;
int ii;
unsigned char ybuf[10241024];
unsigned char chrombuf[10241024];
unsigned char outimg[640480];
index_y = 0;
index_uv = 0;
index_v = 0;
num = (640 480 ) 2 - 4 ;
for(ii=0; ii<num; ii=ii+4)
{
ybuf[index_y++] = frame[ii];
chrombuf[index_uv++]= frame[ii + 1];
ybuf[index_y++]= frame[ii + 2];
chrombuf[index_uv++] = frame[ii + 3];
}
fcvColorYCbCr422PseudoPlanarToRGB565u8 (ybuf,chrombuf,640,480,0,0,outimg,0);
int file_fd;
int write_size;
//struct v4l2_frmsizeenum frame_size;
//struct v4l2_fmtdesc image_fmt;
if ((file_fd = open("outimg.img",O_CREAT | O_RDWR | O_APPEND,777)) == -1)
{
printf("create a picture file error!\n");
}
write_size=write(file_fd,outimg,sizeof(outimg));
printf("write_size = %d\n",write_size);
// Rgb565ConvertBmp((char)outimg,640,480, "test.bmp");
close(file_fd);
}
int main(){
char sVersion[32];
unsigned char ybuf = (unsigned char )malloc(1024600);
fcvGetVersion(sVersion, 32);
printf("FastCV version %s\n", sVersion);
FILE fpyuv = fopen("640x480_yuyv422.yuv", "rb");
if(fpyuv==NULL){
printf("Error open files.\n");
return -1;
}
int size=fread(ybuf, 1, (6001024), fpyuv);
printf("read %d \n",size);
yuvgetfromfrmae(ybuf);
fclose(fpyuv);
free(ybuf);
}
ifdef __cplusplus
}
endif
src下有源码,inc有头文件,usr/lib下libfastcv.a 使用静态库
Makefile如下
##### Make sure all is the first target.
all:
CXX ?= g++
CC ?= gcc
CFLAGS += -g -pthread -Wall
CFLAGS += -rdynamic -funwind-tables
CFLAGS += -I${SDKTARGETSYSROOT}/usr/include/linux-headers/usr/include
CFLAGS += -I./inc
CFLAGS += -I./usr/include
CFLAGS += -D__unused="__attribute__((__unused__))"
#LDFLAGS += -L./usr/lib/gpac
LDFLAGS += -lfastcv
LDFLAGS += -L./lib
LDFLAGS += -ldl
LDFLAGS += -lz -lm
C_SRC=
CXX_SRC=
CXX_SRC +=src/mybmp.cpp
CXX_SRC +=src/getver.cpp
OBJ=
DEP=
#LDFLAGS+= -lcamera
OBJ_CAM_SRV = src/getver.o
TARGETS += getver
$(TARGETS): $(OBJ_CAM_SRV)
TARGET_OBJ += $(OBJ_CAM_SRV)
FILE_LIST := files.txt
COUNT := ./make/count.sh
MK := $(word 1,$(MAKEFILE_LIST))
ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
OBJ=$(CXX_SRC:.cpp=.o) $(C_SRC:.c=.o)
DEP=$(OBJ:.o=.d) $(TARGET_OBJ:.o=.d)
CXXFLAGS += -std=c++11 $(CFLAGS)
#include ./common.mk
.PHONY: all clean distclean
all: $(TARGETS)
clean:
rm -f $(TARGETS) $(FILE_LIST)
find . -name "*.o" -delete
find . -name "*.d" -delete
distclean:
rm -f $(TARGETS) $(FILE_LIST)
find . -name "*.o" -delete
find . -name "*.d" -delete
-include $(DEP)
%.o: %.c $(MK) $(ME)
@[ -f $(COUNT) ] && $(COUNT) $(FILE_LIST) $^ || true
@$(CC) -c $< -MM -MT $@ -MF $(@:.o=.d) $(CFLAGS) $(LIBQCAM_CFLAGS)
$(CC) -c $< $(CFLAGS) -o $@ $(LIBQCAM_CFLAGS)
%.o: %.cpp $(MK) $(ME)
@[ -f $(COUNT) ] && $(COUNT) $(FILE_LIST) $^ || true
@$(CXX) -c $< -MM -MT $@ -MF $(@:.o=.d) $(CXXFLAGS)
$(CXX) -c $< $(CXXFLAGS) -o $@
$(TARGETS): $(OBJ)
$(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS)
@[ -f $(COUNT) -a -n "$(FILES)" ] && $(COUNT) $(FILE_LIST) $(FILES) || true
@[ -f $(COUNT) ] && $(COUNT) $(FILE_LIST) || true
虽然生成的图有问题,但是验证fastcvapi可用