Hello Mat

 找回密码
 立即注册
查看: 10532|回复: 2

按回车键保存图片至指定文件下

[复制链接]

10

主题

15

帖子

0

金钱

新手上路

Rank: 1

积分
15
发表于 2016-10-26 17:21:04 | 显示全部楼层 |阅读模式
  1. #include<opencv2\core\core.hpp>
  2. #include<opencv2\highgui\highgui.hpp>
  3. #include<cv.h>
  4. #include<iostream>

  5. using namespace std;
  6. using namespace cv;

  7. int main()
  8. {
  9.         Mat Img1;
  10.         Mat Img2;
  11.         Mat Img3;
  12.         int m=0;
  13.         char files[30];
  14.         VideoCapture cap;
  15.         cap.open(1);//打开摄像头
  16.         while (cap.isOpened())
  17.         {
  18.                 cap>>Img1;
  19.                 rectangle(Img1,Point(0,0),Point(150,150),Scalar(255,0,0),1,0);
  20.                 Img2=Img1(Rect(0,0,150,150));//抠出图片指定区域
  21.                 resize(Img2,Img3,Size(Img2.rows/3,Img2.cols/3),0,0,1);
  22.                 imshow("yuanshitu",Img1);
  23.                 imshow("jianqie",Img2);
  24.                 imshow("suofang",Img3);
  25.                 char c=waitKey(35);
  26.                 //按回车键拍照保存图片至指定文件夹
  27.                 if(c==13)
  28.                 {       
  29.                         sprintf(files,"E:\\C++/Testpicture/%d.jpg",m);
  30.                         imwrite(files,Img3);
  31.                         m++;
  32.                         cout<<files<<endl;
  33.                 }

  34.         }
  35.         return 0;
  36. }
复制代码

回复

使用道具 举报

1369

主题

1607

帖子

10

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22881
发表于 2016-10-26 21:20:50 | 显示全部楼层
  1. static uint8_t sendInfos[122] = {0};
  2. void AlgorithmProcessFun(uint8_t* frameBuf, uint16_t bufLen, uint16_t nChirpIndex)
  3. {
  4.         uint16_t nSamplesPerChip = (DataProc_GetRadarDataLen() - 8) / 4;
  5.         uint8_t* dataBuf = frameBuf + 12;
  6.         if((RadarPara.dataType == DATA_TYPE_FFT) ||
  7.                 (RadarPara.dataType == DATA_TYPE_DSRAW))
  8.         {
  9.                 for(int j = 0; j < nSamplesPerChip; j ++)
  10.                 {
  11.                         uint8_t temp = dataBuf[4 * j];
  12.                         dataBuf[4 * j] = dataBuf[4 * j + 1];
  13.                         dataBuf[4 * j + 1] = temp;
  14.                                        
  15.                         temp = dataBuf[4 * j + 2];
  16.                         dataBuf[4 * j + 2] = dataBuf[4 * j + 3];
  17.                         dataBuf[4 * j + 3] = temp;
  18.                 }       
  19.                
  20.                 COMPLEX16_T* pData = (COMPLEX16_T*)dataBuf;
  21.                
  22.                 if(nChirpIndex==0 && IsFinished == 0)
  23.                 {
  24.                         IsFinished=1;
  25.                         flagFullFrame = 0;
  26.                         //maxPower = 0;
  27.                         memset(flagfullFrameIndex, 0, sizeof(flagfullFrameIndex));
  28.                         flagfullFrameIndex[0] = 1;
  29.                         memset(RadarReal, 0, sizeof(RadarReal));
  30.                         memset(RadarImag, 0, sizeof(RadarImag));
  31.                         for(int j=0;j<10;j++)
  32.                         {
  33.                                 RadarReal[j][nChirpIndex] = pData[j].real;
  34.                                 RadarImag[j][nChirpIndex] = pData[j].imag;
  35.                         }
  36.                 }
  37.                 else if(nChirpIndex>0 &&nChirpIndex<64 && IsFinished==1)
  38.                 {
  39.                         flagFullFrame++;
  40.                         flagfullFrameIndex[nChirpIndex] = 1;
  41.                         for(int j=0;j<10;j++)
  42.                         {
  43.                                 RadarReal[j][nChirpIndex] = pData[j].real;
  44.                                 RadarImag[j][nChirpIndex] = pData[j].imag;
  45.                         }
  46.                         memset(RadarSumRPower, 0, sizeof(RadarSumRPower));
  47.                   memset(RadarSumRPowerM, 0, sizeof(RadarSumRPowerM));
  48.                   memset(RadarBreathReal, 0, sizeof(RadarBreathReal));
  49.                   memset(RadarBreathImag, 0, sizeof(RadarBreathImag));
  50.                         memset(sendInfos, 0, sizeof(sendInfos));
  51.                 }

  52.                 uint8_t sum = 0;
  53.                 for(int j=0;j<64;j++)
  54.                 {
  55.                         sum = sum+flagfullFrameIndex[j];
  56.                 }
  57.                 if(sum==64 && flagFullFrame>=63)
  58.                 {
  59.                         for(int j=0;j<10;j++)
  60.                         {
  61.                                 int32_t sumReal = 0;
  62.                                 int32_t sumImag = 0;
  63.                                 uint32_t sumPower = 0;
  64.                                 uint32_t sumPower2 = 0;
  65.                                 for(int i=0;i<64;i++)
  66.                                 {
  67.                                         int16_t realv = RadarReal[j][i];
  68.                                         int16_t imagv = RadarImag[j][i];
  69.                                         sumReal = sumReal + realv;
  70.                                         sumImag = sumImag + imagv;
  71.                                         uint32_t sumAmp = (uint32_t)((int32_t)(realv*realv) + (int32_t)(imagv*imagv));
  72.                                         sumPower2 = sumPower2 + sumAmp;
  73.                                         sumPower = sumPower + (uint32_t)sqrt_fast(sumAmp);
  74.                                 }
  75.                                 RadarBreathReal[j] = (int16_t)(sumReal/64);
  76.                                 RadarBreathImag[j] = (int16_t)(sumImag/64);
  77.                                 RadarSumRPower[j] = (uint32_t)(sumPower/64);
  78.                                 // &#199;ó·&#189;&#178;&#238;, std
  79.                                 //Ampliptude[j] = (sumPower2/64)-RadarSumRPower[j]*RadarSumRPower[j];
  80.                                
  81.                                 // fft - speed
  82.                                 int16_t fft_buffer[128];
  83.                                 int16_t fft_mag_buffer[64];
  84.                                 for(int i=0;i<64;i++)
  85.                                 {
  86.                                         fft_buffer[2*i] = (int16_t)(RadarReal[j][i] - RadarBreathReal[j]);
  87.                                         fft_buffer[2*i+1] = (int16_t)(RadarImag[j][i] - RadarBreathImag[j]);
  88.                                 }
  89.                           arm_cfft_q15(&arm_cfft_sR_q15_len64, fft_buffer, 0, 1);
  90.                                 arm_cmplx_mag_q15(fft_buffer, fft_mag_buffer, 64);
  91.                                 // &#188;&#198;&#203;&#227;fft &#198;&#189;&#190;ù&#214;&#181;
  92.                                 int32_t sumMotion = 0;
  93.                                 for(int i=0;i<64;i++)
  94.                                 {
  95.                                         sumMotion = sumMotion + fft_mag_buffer[i];
  96.                                 }
  97.                                 RadarSumRPowerM[j] = (uint32_t)(sumMotion/64);
  98.                         }
  99.                         // send
  100.                         sendInfos[0] = 0xFA;
  101.                         memcpy(&sendInfos[1], &RadarBreathReal[0], 20);  // int16_t -- 2 x uint8_t
  102.                         memcpy(&sendInfos[21], &RadarBreathImag[0], 20);  // int16_t -- 2 x uint8_t
  103.                         memcpy(&sendInfos[41], &RadarSumRPower[0], 40);  // uint32_t -- 4 x uint8_t
  104.                         memcpy(&sendInfos[81], &RadarSumRPowerM[0], 40);  // uint32_t -- 4 x uint8_t
  105.                         sendInfos[121] = 0xF1;
  106.                         //
  107.                         //Delay(40);
  108.                         while(!uart_is_Ready()){};
  109.       uart_transmit(sendInfos, 122);
  110.                         //
  111.                         flagFullFrame = 0;
  112.                         memset(flagfullFrameIndex, 0, sizeof(flagfullFrameIndex));
  113.                         IsFinished=0;
  114.                 }
  115.                
  116.         }
  117. }
复制代码

算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复 支持 反对

使用道具 举报

10

主题

15

帖子

0

金钱

新手上路

Rank: 1

积分
15
 楼主| 发表于 2016-10-27 09:51:11 | 显示全部楼层
Halcom 发表于 2016-10-26 21:20
你的opencv版本,摄像头是电脑摄像头么?

我的电脑的摄像头坏了,用的是USB外部摄像头
cap.open(1)
这个地方,一般0打开电脑自带摄像头,大于0表示打开外部摄像头,小于0表示手动选择摄像头
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2026-6-25 10:08 , Processed in 0.160531 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表