糖果派对官方网站_可以赌钱的糖果游戏_手机版
依附OpenCV和QT,建构Android图像处理程序

依附OpenCV和QT,建构Android图像处理程序

作者:网络编程    来源:未知    发布时间:2019-12-24 21:03    浏览量:

原稿地址大器晚成、综述怎样收罗图片?在windows情状下,大家可以应用dshow,在linux下,也可能有ffmpeg等幼功类库,再不济,opencv自带的videocapture也是提供了底蕴的支撑。那么在andoird下,使用的确定是Android自带的连带函数了。由于Android是基于java语言的,固然大家想要调用Android的连锁函数,那么必得透过JNI的点子。这里有能够分为二种,意气风发种是平昔在java中得以完成相比完整的函数,在qt中,只必要调用这么些函数就足以;另生机勃勃种即是利用qt自带的jni机制,举例上面那样,张开摄像头,并且搜聚图片。大家首先介绍第二种方法,让大家最快步入情形。二、通过JNI展开摄像头a、填加头文件和命名空间,定义公共变量和宏:#includeQtAndroid#includeQDebug#includeQAndroidJniEnvironment#includeQAndroidActivityResultReceiver#includeQDateTime#includeQFileusingnamespacecv;usingnamespaceQtAndroid;QStringstrFetchImage="";QStringselectedFileName="";#defineCHECK_EXCEPTION()if(env-ExceptionCheck()){qDebug()"exceptionoccured";env-ExceptionClear();}此中须要小心的是,CHECK_EXCEPTION是用来检查Android系统是或不是有十二分的。那一点在运用JNI的时候极其主要和必备。b、填加回调类,首要便是在一文山会海特别判别后,获得imagepath。该类集成自ResultReceiver:classResultReceiver:publicQAndroidActivityResultReceiver{public:ResultReceiver(QStringimagePath,QLabel*view):m_imagePath(imagePath),m_imageView(view){}voidhandleActivityResult(intreceiverRequestCode,intresultCode,constQAndroidJniObjectdata){qDebug()"handleActivityResult,requestCode-"receiverRequestCode"resultCode-"resultCode"data-"data.toString();if(resultCode==-1receiverRequestCode==1){qDebug()"capturedimageto-"m_imagePath;qDebug()"capturedimageexist-"QFile::exists(m_imagePath);m_imageView-setPixmap(QPixmap(m_imagePath));}}QStringm_imagePath;QLabel*m_imageView;};C、填加控件触发事件。日常的话大家接收pressed事件d、编写拍照代码//张开摄像头,采撷图片voidMainWindow::on_btn_capture_pressed(卡塔尔国{ui-lbMain-setScaledContents(true卡塔尔国;//显示的图像自动缩放b_canSave=false;//图片并未有收集达成,近日不可能保存//援用JNIQAndroidJniEnvironmentenv;//创制用于展开录制头的contentQAndroidJniObjectaction=QAndroidJniObject::fromString("android.media.action.IMAGE_CAPTURE");QAndroidJniObject(intent("android/content/Intent","(Ljava/lang/String;)V",action.objectjstring());//设定img路径QStringdate=QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss");QAndroidJniObjectfileName=QAndroidJniObject::fromString(date+".jpg");QAndroidJniObjectsavedDir=QAndroidJniObject::callStaticObjectMethod("android/os/Environment","getExternalStorageDirectory","()Ljava/io/File;");//使用CHECK_EXCEPTION管理特别CHECK_EXCEPTION()qDebug()"savedDir-"savedDir.toString();QAndroidJniObjectsavedImageFile("java/io/File","(Ljava/io/File;Ljava/lang/String;)V",savedDir.objectjobject(),fileName.objectjstring());CHECK_EXCEPTION()qDebug()"savedImageFile-"savedImageFile.toString();QAndroidJniObjectsavedImageUri=QAndroidJniObject::callStaticObjectMethod("android/net/Uri","fromFile","(Ljava/io/File;)Landroid/net/Uri;",savedImageFile.objectjobject());CHECK_EXCEPTION(卡塔尔//将出口路线传递过来QAndroidJniObjectmediaStoreExtraOutput=QAndroidJniObject::getStaticObjectField("android/provider/MediaStore","EXTRA_OUTPUT","Ljava/lang/String;");CHECK_EXCEPTION()qDebug()"MediaStore.EXTRA_OUTPUT-"mediaStoreExtraOutput.toString(卡塔尔(英语:State of Qatar);intent.callObjectMethod("putExtra","(Ljava/lang/String;Landroid/os/Parcelable;卡塔尔国Landroid/content/Intent;",mediaStoreExtraOutput.objectjstring(卡塔尔(英语:State of Qatar),savedImageUri.objectjobject(卡塔尔(قطر‎卡塔尔(英语:State of Qatar);//得到收罗图片的相对路线,并且展现出来ResultReceiver*resultReceiver=newResultReceiver(savedImageFile.toString(卡塔尔(قطر‎,ui-lbMain卡塔尔(قطر‎;startActivity(intent,1,resultReceiver卡塔尔国;//得到再次回到的断然地址(注意那句话明确要写在CHECK_EXCEPTION中)strFetchImage=savedImageFile.toString(卡塔尔国;}最后搜罗到的图样地址保存在strFetchImage中e、编写管理代码。由于本人这里关键实行的是图像管理操作,所以必得结合OpenCV相关函数实行//图像管理操作voidMainWindow::on_btn_process_pressed(){b_canSave=false;if(strFetchImage!=""卡塔尔{ui-lbMain-setScaledContents(false卡塔尔;Matsrc=imread(strFetchImage.toStdString(卡塔尔(قطر‎卡塔尔国;Matsrc2;Matrotated;////////////////////////////首要算法/////////////////////////////cv::resize(src,src2,cv::Size(720,1000卡塔尔(英语:State of Qatar)卡塔尔国;//标准大小Matsrc_gray;Matsrc_all=src2.clone();Matthreshold_output;vectorvectorPointcontours,contours2;vectorVec4ihierarchy;//预处理cvtColor(src2,src_gray,CV_BGR2GRAY);blur(src_gray,src_gray,Size(3,3卡塔尔(英语:State of Qatar)卡塔尔(英语:State of Qatar);//模糊,去除毛刺threshold(src_gray,threshold_output,100,255,THRESH_OTSU卡塔尔国;//增添提示ui-lb_info-setText("伊始寻觅轮廓!"卡塔尔国;//找寻概况//第三个参数是输入图像2值化的//第一个参数是内部存款和储蓄器存储器,FindContours找到的大约放到内部存款和储蓄器里面。//第多个参数是层级,**[Next,Previous,First_Child,Parent]**的vector//第三个参数是项目,选用树构造//第四个参数是节点拟合形式,这里是一切找出findContours(threshold_output,contours,hierarchy,CV_RETR_TREE,CHAIN_APPROX_NONE,Point(0,0卡塔尔国卡塔尔国;//加多提醒if(contours.size(卡塔尔(英语:State of Qatar)=10卡塔尔(英语:State of Qatar){ui-lb_info-setText("概况筛选错误,循环退出!请重新搜集数据。"卡塔尔国;return;}else{ui-lb_info-setText("开端寻觅轮廓!起始筛选轮廓!"卡塔尔(英语:State of Qatar);}//轮廓筛选intc=0,ic=0,area=0;intparentIdx=-1;for(inti=0;icontours.size(卡塔尔(英语:State of Qatar);i++卡塔尔国{//hierarchy[i][2]!=-1代表不是最外面包车型客车概况if(hierarchy[i][2]!=-1ic==0){parentIdx=i;ic++;}elseif(hierarchy[i][2]!=-1卡塔尔(英语:State of Qatar){ic++;}//最外侧的清0elseif(hierarchy[bb电子糖果派对,i][2]==-1卡塔尔(قطر‎{ic=0;parentIdx=-1;}//找到定位点音讯if(ic=2卡塔尔{contours2.push_back(contours[parentIdx]卡塔尔;ic=0;parentIdx=-1;}}//增加提醒if(contours2.size(卡塔尔3卡塔尔(英语:State of Qatar){ui-lb_info-setText("定位点选择不当,循环退出!请重新搜聚数据。"卡塔尔国;return;}else{ui-lb_info-setText("开头物色概况!以前筛选轮廓!定位点选用正确!"卡塔尔;}//填充定位点,大家约定,必定要能力所能达到同不时候识别出4个点来for(inti=0;icontours2.size(卡塔尔;i++卡塔尔drawContours(src_all,contours2,i,CV_传祺GB(0,255,0卡塔尔(英语:State of Qatar),-1卡塔尔(英语:State of Qatar);//识别出来了重要区域,可是多少不对,展现当前识别结果,退出循环if(contours2.size(卡塔尔(英语:State of Qatar)!=4){QPixmapqpixmap=Mat2QImage(src_all);ui-lbMain-setPixmap(qpixmap);ui-lb_info-setText("定位点数量不为4!请重新收集数据。"卡塔尔国;return;}else{//不然,进一层细分Pointpoint[4];for(inti=0;icontours2.size(卡塔尔国;i++卡塔尔{//筛选轮廓,doubled=contourArea(contours2[i]);if(d720*1000/4){ui-lb_info-setText("采聚焦有错误轮廓,请重新采撷数据"卡塔尔(英语:State of Qatar);QPixmapqpixmap=Mat2QImage(src_all卡塔尔;ui-lbMain-setPixmap(qpixmap卡塔尔(قطر‎;return;}//定位主要,仁同一视复排序Pointptmp=Center_cal(contours2,i);if(ptmp.x720/4ptmp.y1000/4){point[0]=ptmp;}elseif(ptmp.x720/4ptmp.y1000/4){point[2]=ptmp;}elseif(ptmp.x720/4ptmp.y1000/4){point[1]=ptmp;}else{point[3]=ptmp;}}//打字与印刷出来for(inti=0;i3;i++卡塔尔国{charcbuf[100];sprintf(cbuf,"%d",i+1);putText(src_all,cbuf,point[i],FONT_HERSHEY_PLAIN,5,Scalar(0,0,0),5);ui-lb_依附OpenCV和QT,建构Android图像处理程序。info-setText("结果识别精确,能够保存"卡塔尔(英语:State of Qatar);}//透视调换cv::Point2fsrc_vertices[4];src_vertices[0]=point[0];src_vertices[1]=point[1];src_vertices[2]=point[2];src_vertices[3]=point[3];Point2fdst_vertices[4];dst_vertices[0]=Point(0,0);dst_vertices[1]=Point(720,0);dst_vertices[2]=Point(0,1000);dst_vertices[3]=Point(720,1000);MatwarpMatrix=getPerspectiveTransform(src_vertices,dst_vertices卡塔尔国;//试行透视变化warpPerspective(src2,rotated,warpMatrix,rotated.size(卡塔尔(英语:State of Qatar),INTECR-V_LINEAR,BORDER_CONSTANT卡塔尔国;}//////////////////////////END首要算法END/////////////////////////将图片展示到label上QPixmapqpixmap=Mat2QImage(rotated卡塔尔(英语:State of Qatar);ui-lbMain-setPixmap(qpixmap卡塔尔(قطر‎;matResult=rotated.clone(卡塔尔;b_canSave=true;}}三、开首结果和后续钻探需求缓慢解决的题材依照陈设,近年来拿到那样的结果下一步重视解决以下难题1、升高程序稳固性;2、进步分界面流程性和周转速度;3、重构代码,进一层进展包装;4、增添数量保存的有关职能。感激阅读至此,希望全体助于!

bb电子糖果派对 1

代码如下,时间计算大器晚成帧5000ms,试过并行运转,只优化400ms。。#includeopencv2/nonfree/features2d.hpp//使用SiftFeatureDetector供给丰硕此头文件#includeopencv2opencv.hpp#includeiostream#includefstream#include"iostream"#include"highgui.h"#include"cv.h"#include"cxcore.h"#includeopencv/cxcore.husingnamespacecv;usingnamespacestd;#defineERROR1234CvBox2DBox2D;voiddrawCross(CvArr*img,CvPoint2D32fpoint,CvScalarcolor,intsize,intthickness卡塔尔(英语:State of Qatar){//绘制横线cvLine(img,cvPoint(point.x-size/2,point.y卡塔尔(قطر‎,cvPoint(point.x+size/2,point.y卡塔尔国,color,thickness,8,0卡塔尔(قطر‎;//绘制竖线cvLine(img,cvPoint(point.x,point.y-size/2卡塔尔,cvPoint(point.x,point.y+size/2卡塔尔(英语:State of Qatar),color,thickness,8,0卡塔尔(قطر‎;return;}CvSeq*GetAreaMaxContour(CvSeq*contour卡塔尔(قطر‎{//在给定的contour中找到面积最大的三个差超级少,并重临指向该轮廓的指针doublecontour_area_temp=0,contour_area_max=0;CvSeq*area_max_contour=0;//指向面积最大的概略CvSeq*c=0;//printf("TotalContoursDetected:%dn",Nc);for(c=contour;c!=NULL;c=c-h_next卡塔尔(英语:State of Qatar){//寻找面积最大的概貌,即循环甘休时的area_max_contourcontour_area_temp=fabs(cvContourArea(c,CV_WHOLE_SEQ卡塔尔(قطر‎卡塔尔;//获取当前大致面积if(contour_area_tempcontour_area_max){contour_area_max=contour_area_temp;//找到面积最大的概况area_max_contour=c;//记录面积最大的大约}}returnarea_max_contour;}voidgetCenter(IplImage*img){IplImage*src=img;intdata[16]={0,0,0,0,0,0,1,0,///图像的腐蚀0,1,1,0,0,0,0,0};IplConvKernel*Element=cvCreateStructuringElementEx(4,4,2,2,CV_SHAPE_RECT,data);;cvSmooth(src,src,CV_MEDIAN,5,5,0,0);cvErode(src,src,Element,2);//***********************************************/IplImage*src_RGB=cvCreateImage(cvGetSize(src),8,3);IplImage*ZeroImage=cvCreateImage(cvGetSize(src),8,3);cvZero(ZeroImage);src_RGB=cvCloneImage(src);//copyImageIplImage*src_gray=cvCreateImage(cvGetSize(src),8,1);IplImage*Canny_Image=cvCreateImage(cvGetSize(src),8,1);IplImage*Threshold=cvCreateImage(cvGetSize(src),8,1);cvCvtColor(src,src_gray,CV_RGB2GRAY);//cvNamedWindow("GRAY",0);//cvResizeWindow("GRAY",500,500);//cvShowImage("GRAY",src_gray卡塔尔(英语:State of Qatar);//显示中黄图像//转为二值化图像cvThreshold(src_gray,Threshold,150,255,CV_THRESH_BINAMuranoY卡塔尔国;//参数调解阈值大小影响图像取轮廓150阈值//cvNamedWindow("Threshold",0卡塔尔;//cvResizeWindow("Threshold",500,500卡塔尔国;//cvShowImage("Threshold",Threshold);CvMemStorage*storage=cvCreateMemStorage(0);CvSeq*Image_Seq;//使用canny算法提取图像的轮廓cvCanny(Threshold,Canny_Image,125,255,3卡塔尔;//使用cvfindcontour函数提取概况cvFindContours(Canny_Image,storage,Image_Seq,sizeof(CvContour),CV_RETR_CCOMP,CV_CHAIN_APPROX_NONE);cvDrawContours(src_RGB,Image_Seq,CV_RGB(200,65,45),CV_RGB(100,165,45),2,2,8);cvDrawContours(ZeroImage,Image_Seq,CV_RGB(200,65,45),CV_RGB(255,2555,255),2,2,8);CvSeq*Cal_Contours=GetAreaMaxContour(Image_Seq);CvPoint2D32fArray[4];for(;Cal_Contours!=0;Cal_Contours=Cal_Contours-h_next){//showAngletoImageCvSeq*InterCon=Cal_Contours-v_next;for(;InterCon!=0;InterCon=InterCon-h_next){Box2D=cvMinAreaRect2(Cal_Contours);CvBox2DFitBox;FitBox=cvMinAreaRect2(Cal_Contours);//cvFitEllipse2(Cal_Contours);//printf("Cal_Contoursofangle%f",Box2D.angle);CvBox2Dellipse=cvFitEllipse2(Cal_Contours);cvBoxPoints(FitBox,Array);cvEllipseBox(src_RGB,ellipse,CV_CRUISERGB(255,255,0卡塔尔(قطر‎卡塔尔;//在图上画椭圆printf("%f%f",Array[0].x,Array[0].y);floata=(Array[0].x+Array[1].x+Array[2].x+Array[3].x)/4;floatb=(Array[0].y+Array[1].y+Array[2].y+Array[3].y)/4;printf("%f%f",a,b);printf("n");cvLine(ZeroImage,cvPoint(Array[0].x,Array[0].y),cvPoint(Array[1].x,Array[1].y),CV_RGB(114,45,255),2,8);cvLine(ZeroImage,cvPoint(Array[1].x,Array[1].y),cvPoint(Array[2].x,Array[2].y),CV_RGB(114,45,255),2,8);cvLine(ZeroImage,cvPoint(Array[2].x,Array[2].y),cvPoint(Array[3].x,Array[3].y),CV_RGB(114,45,255),2,8);cvLine(ZeroImage,cvPoint(Array[3].x,Array[3].y),cvPoint(Array[0].x,Array[0].y),CV_LANDGB(114,45,255卡塔尔(英语:State of Qatar),2,8卡塔尔国;drawCross(ZeroImage,Box2D.center,cvScalar(0,0,255卡塔尔(قطر‎,200,10卡塔尔国;//十字中式茶食//在图上画圆//cvCircle(ZeroImage,cvPoint((int卡塔尔国Box2D.center.x,(int卡塔尔(قطر‎Box2D.center.y卡塔尔(英语:State of Qatar),50,CV_RGB(45,89,56),2,8);////drawRectAngletoImage//CvRectrect=cvBoundingRect(Cal_Contours);//cvRectangle(ZeroImage,cvPoint(rect.x,rect.y),cvPoint(rect.x+rect.width,rect.y+rect.width),CV_TiguanGB(114,45,255卡塔尔(英语:State of Qatar),2,8卡塔尔(英语:State of Qatar);}}//突显图像cvNamedWindow("ZeroImage",0卡塔尔;cvResizeWindow("ZeroImage",500,500卡塔尔国;cvShowImage("ZeroImage",ZeroImage卡塔尔(قطر‎;//cvNamedWindow("src",0卡塔尔(英语:State of Qatar);//cvResizeWindow("src",500,500卡塔尔(قطر‎;//cvShowImage("src",Canny_Image);//cvNamedWindow("src_RGB",0);//cvResizeWindow("src_RGB",500,500);//cvShowImage("src_RGB",src_RGB);return;}intgetSift(IplImage*img){Matc_src2(img,true);Matc_src1=imread("s2.jpg");Matsrc1=imread("s2.jpg",CV_LOAD_IMAGE_GRAYSCALE);Matsrc2;cvtColor(c_src2,src2,CV_RGB2GRAY);if(!src1.data||!src2.data){std::cout"--(!)Errorreadingimages"std::endl;return-1;}///***************************************************//siftfeaturedetectSurfFeatureDetectordetector;vectorKeyPointkp1,kp2;detector.detect(src1,kp1);detector.detect(src2,kp2);SurfDescriptorExtractorextractor;Matdes1,des2;//descriptorextractor.compute(src1,kp1,des1);extractor.compute(src2,kp2,des2);Matres1,res2;intdrawmode=DrawMatchesFlags::DRAW_RICH_KEYPOINTS;drawKeypoints(c_src1,kp1,res1,Scalar::all(-1卡塔尔国,drawmode卡塔尔国;//在内部存款和储蓄器中画出特征点drawKeypoints(c_src2,kp2,res2,Scalar::all(-1),drawmode);cout"sizeofdescriptionofImg1:"kp1.size()endl;cout"sizeofdescriptionofImg2:"kp2.size()endl;BFMatchermatcher(NORM_L2);vectorDMatchmatches;matcher.match(des1,des2,matches);Matimg_match;drawMatches(src1,kp1,src2,kp2,matches,img_match卡塔尔国;//,Scalar::all(-1卡塔尔(英语:State of Qatar),Scalar::all(-1卡塔尔(英语:State of Qatar),vectorchar(卡塔尔(英语:State of Qatar),drawmode卡塔尔(英语:State of Qatar);//coutkp1.at(matches.at(1卡塔尔国.queryIdx卡塔尔.angleendl;//coutkp2.at(matches.at(1卡塔尔国.trainIdx卡塔尔.angleendl;//投票表决,拿到左近的角度intangle_count[361]={0};intcount=0;#pragmaompparallelforfor(inti=0;imatches.size();i++){intindex=kp2.at(matches.at(i).trainIdx).angle-kp1.at(matches.at(i).queryIdx).angle+0.5;//fileokp2.at(matches.at(i).trainIdx).angle-kp1.at(matches.at(i).queryIdx).angleendl;index=index0?index:index+360;//coutindexendl;angle_count[index]++;}intmaxindex=0;#pragmaompparallelforfor(inti=0;i361;i++){//couti""angle_count[i]endl;if(angle_count[i]=angle_count[maxindex]卡塔尔(英语:State of Qatar){maxindex=i;}}maxindex=(maxindex-360卡塔尔0?maxindex:(maxindex-360卡塔尔(قطر‎;cout"旋转角度:"maxindex-1endl;//对临界点的拍卖,存在一些主题材料intdown,up;down=maxindex-10?maxindex:maxindex-1;up=maxindex+1360?maxindex:maxindex+1;doubleangle=0;count=0;#pragmaompparallelforfor(inti=0;imatches.size(卡塔尔国;i++卡塔尔{doubletemp=kp2.at(matches.at(i卡塔尔.trainIdx卡塔尔(英语:State of Qatar).angle-kp1.at(matches.at(i卡塔尔.queryIdx卡塔尔国.angle;if(temp=downtemp=up卡塔尔(قطر‎{count++;angle+=temp;}}angle/=count;cout"准确角度:"angle-0.2endl;cout"numberofmatchedpoints:"matches.size(卡塔尔国endl;cvNamedWindow("matches",0卡塔尔(قطر‎;cvResizeWindow("matches",500,500卡塔尔(英语:State of Qatar);imshow("matches",img_match);////////////////////////////中心点return0;}intmain(intargc,char*argv[]){//ofstreamfileo("data.txt");IplImage*pFrame=NULL;//获取录像头CvCapture*pCapture=cvCreateCameraCapture(-1卡塔尔;//创制窗口cvNamedWindow("video",0卡塔尔(قطر‎;cvResizeWindow("video",640,480卡塔尔(قطر‎;//彰显视屏while(true卡塔尔(英语:State of Qatar){doublestart,end,t1,t2;start=(double卡塔尔(英语:State of Qatar)cvGetTickCount(卡塔尔(قطر‎;//记下起来的石英钟计数,以便总结函数或顾客代码实施时间pFrame=cvQueryFrame(pCapture卡塔尔(قطر‎;if(!pFrame)break;cvShowImage("video",pFrame);IplImage*img=pFrame;getCenter(img卡塔尔(قطر‎;getSift(img卡塔尔(قطر‎;if(waitKey(33卡塔尔=='q'卡塔尔(قطر‎break;end=(double卡塔尔(英语:State of Qatar)cvGetTickCount(卡塔尔;//记下结束的挂钟计数t1=(end-start卡塔尔(英语:State of Qatar)/((double卡塔尔国cvGetTickFrequency(卡塔尔(قطر‎*1000.卡塔尔(英语:State of Qatar);//总结运维时刻,以纳秒为单位printf("RuntimewithoutOpenMP=%gmsn",t1);}cvReleaseCapture(pCapture);cvDestroyWindow("video");cvWaitKey();return0;}

友情链接: 网站地图
Copyright © 2015-2019 http://www.tk-web.com. bb电子糖果派对有限公司 版权所有