我正在开发一个 android 应用程序,它逐帧处理实时摄像机流(以检测正方形)。在预览回调中,它将图像帧作为字节数组传递。在我的 opencv 函数中,它将字节数组转换为 mat 对象。我需要mixchannels()
在 opencv 中使用函数。我认为我的 mat 对象不兼容,mixchannels()
因为它在那里击中。任何建议如何解决它。当我image
用image1
它替换时,那里也击中。请帮助。谢谢你,祝你有美好的一天!这是我的代码。
JNIEXPORT jint JNICALL Java_org_opencv_samples_tutorial3_Sample3View_FindFeatures(JNIEnv* env, jobject thiz, jint width, jint height, jbyteArray yuv, jintArray rgba)
{
jbyte* _yuv = env->GetByteArrayElements(yuv, 0);
jint* _rgba = env->GetIntArrayElements(rgba, 0);
//Mat myuv(height + height/2, width, CV_8UC1, (unsigned char *)_yuv);
Mat image(height + height/2, width, CV_8UC1, (unsigned char *)_yuv);//byte array in to mat object
Mat image1(height + height/2, width, CV_8UC3, (unsigned char *)_yuv);
Mat mrgba(height, width, CV_8UC4, (unsigned char *)_rgba);
Mat mgray(height, width, CV_8UC1, (unsigned char *)_yuv);
cvtColor(image, mrgba, CV_YUV420i2RGB ,4);
vector<vector<Point> > squares;//
vector<vector<Point> > contours;//
jint Area=0;
int thresh = 50, N = 10;
Mat pyr, timg, gray0(image.size(), CV_8U), gray;
pyrDown(image, pyr, Size(image.cols/2, image.rows/2));//reduces noice of the image,if i put'image1' here it struck too
pyrUp(pyr, timg, image.size());//reduces noice of the image
//for loop to find squares in every color plane of the image
for( int c = 0; c < 3; c++ )
{
int ch[] = {c, 0};
mixChannels(&timg, 1, &gray0, 1, ch, 1);//code struck here.if i replace 'c' with '1' it workes