Created
October 3, 2016 23:57
-
-
Save arccoder/0a4c84d116b7a21f2264c9cd2a8405a5 to your computer and use it in GitHub Desktop.
Convert RGB color image to Grayscale using FastCV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "fastcv.h" | |
#include <opencv2/core/core.hpp> | |
#include <opencv2/highgui/highgui.hpp> | |
#include <iostream> | |
using namespace cv; | |
using namespace std; | |
int main() | |
{ | |
// OpenCV - Read file | |
Mat imageSrc = imread("imagefile.jpg", IMREAD_COLOR); | |
// FastCV - Source data preparation | |
const uint8_t* __restrict src = imageSrc.data; | |
uint32_t srcWidth = 640; | |
uint32_t srcHeight = 480; | |
uint32_t srcStride = srcWidth * 3; | |
uint8_t* __restrict dst = new uint8_t[srcWidth * srcHeight]; | |
uint32_t dstStride = srcWidth; | |
// FastCV - Initialization (Not required) | |
fcvOperationMode mode = FASTCV_OP_CPU_PERFORMANCE; | |
fcvSetOperationMode(mode); | |
// FastCV - RGB2GRAY | |
fcvColorRGB888ToGrayu8(src, srcWidth, srcHeight, srcStride, dst, dstStride); | |
// FastCV - De-Initialization (Not required) | |
fcvCleanUp(); | |
// OpenCV - Destination data preparation | |
Mat imageDst = Mat(srcHeight, srcWidth, CV_8U, dst); | |
// OpenCV - Display source image | |
imshow("Source Image", imageSrc); | |
waitKey(0); | |
// OpenCV - Display destination image | |
imshow("Destination Image", imageDst); | |
waitKey(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment